Learn how to print the whole array with JS and how to print individual elements of the JS array in both HTML (browser) and Node.js (server-side) environments.

The easiest way to print the JS array is to just pass it into the console.log function.

const reactFrameworks = ['Next.js', 'Gatsby.js', 'CRA'];

console.log(reactFrameworks);  // [ 'Next.js', 'Gatsby.js', 'CRA' ]

If you’re working in a browser, you may be unhappy with the result which is invisible to the user. You can only see the printed array when you open the console.

To make printed array visible on the webpage, you can write the script, that sets innerHTML of some HTML element, for example <p> - paragraph.

<body>
  <p id="printedFrameworks"></p>
  <script>
    const reactFrameworks = ['Next.js', 'Gatsby.js', 'CRA'];
    document.getElementById("printedFrameworks").innerHTML = reactFrameworks;
  </script>
</body>

As a result, you’ll see Next.js,Gatsby.js,CRA in the browser.