Skip to content

JavaScript array to string | toString method()

  • by

Using the toString() method you can convert the array to a string in JavaScript. This method returns a string representing the specified array and its elements.

array.toString()

Note: the toString method can’t be used on an array of objects because it will return [object Object] instead of the actual values.

Convert array to string in JavaScript

Simple example code print array as a string in the console.

  <!DOCTYPE html>
  <html>
  <head>

    <script>
      const array1 = [100, 200, 'AAA', 'BBB'];

      console.log(array1.toString());
    </script>

  </head>
  </html>

Output:

JavaScript array to string

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