Yasin Ahmed
Yasin Ahmed

Reputation: 49

Is there any way to print multiple lines in JS alert box using loop?

Hey guys I want to ask if there is any way to write multiple lines in one JS alert box using for loop? I WANT TO HAVE OUTPUT LIKE THIS WITH ONE STRING VARIABLE AND ANY LOOP

I WANT TO HAVE OUTPUT LIKE THIS WITH ONE STRING VARIABLE AND ANY LOOP, HOW CAN I HAVE OUTPUT LIKE THIS WITH ABOVE MENTIONED REQUIREMENTS?

Upvotes: 0

Views: 770

Answers (1)

Isa
Isa

Reputation: 418

Use \n

alert("String 1\nString 2");

var p = '';

for (var i = 1; i < 5; i++) {
  p+= "string " + i + '\n'
}

alert(p)

Upvotes: 2

Related Questions