0

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?

2
  • Not reliably, no. The ECMAScript specification does not describe how alert() boxes should appear. Long messages will be truncated. Also, using the old-school message-boxes like alert(), confirm() and prompt() are discouraged because they block the UI thread. Consider using HTML5's <dialog> instead. Commented Jun 5, 2020 at 11:58
  • try using 3rd party alert like sweetalert sweetalert2.github.io Commented Jun 5, 2020 at 11:59

1 Answer 1

2

Use \n

alert("String 1\nString 2");

var p = '';

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

alert(p)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.