Skip to content

JavaScript print array on separate lines | Example code

  • by

Use the join() method to combine the array into one string and separate each entry by <br> to print the array on separate lines in JavaScript.

document.getElementById("result").innerHTML =
  schedule.join("<br>");

Example print array on separate lines in JavaScript

Simple example code.

<!DOCTYPE html>
<html>
<body>

  <div id="output">
    <div>Extracting...</div>
  </div>

  <script>

    var arr = ["100", "200", "300"];
    
    document.getElementById("output").innerHTML =
    arr.join("<br>") + "<br>";
  </script>

</body>
</html>

Output:

JavaScript print array on separate lines

How can I print multiple arrays on separate lines using the same console.log?

var a = [2, 4];

var b = [5, 6];

console.log('',a,'\n',b)

Print array elements in a new line console

array = ["Bob", "James", "Taylor"]
for (i = 0; i< array.length; i++){
	console.log(array[i]) }

Do comment if you have any doubts or suggestions on this JS Array print topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading