Skip to content

JavaScript print array to console | Example code

  • by

Just pass the Array object into a console.log() to print the array as comma-separated in JavaScript. And if you want to print array elements wise then use loop (while or for-loop).

Example print array to console in JavaScript

Simple example code prints the array as comma-separated in the console.

  <!DOCTYPE html>

      const fruits = ["Kiwi", "Orange", "Apple", "Mango"];


Output: To see the output in the console use inception mode then select console.

JavaScript print array to console

Print array elements in the console

      const fruits = ["Kiwi", "Orange", "Apple", "Mango"];
      for(let i = 0; i < fruits.length; i++){

Print properties for objects stored in the array

JSON.stringify() method will convert a JavaScript value/object to a JSON string.

      var bannerData = [{item:1},{item:2},{item:3}];

Output: [{“item”:1},{“item”:2},{“item”:3}]

Do comment if you have any doubts or suggestions on this JS print array 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

Your email address will not be published. Required fields are marked *