The Wayback Machine - https://web.archive.org/web/20230512160215/https://www.geeksforgeeks.org/javascript-array-tostring-method/
Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

JavaScript Array toString() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The JavaScript Array toString() Method returns the string representation of the array elements

Syntax:

arr.toString()

Parameters: This method does not accept any parameter.

Return value: 

  • The method returns the string representation of the array elements. 
  • If the array is empty, then it returns an empty string.
  • The original array is not changed by this method

Below is an example of the Array toString() method.

Example 1: 

JavaScript




<script>
    // JavaScript to illustrate toString() method
    function func() {
     
        // Original array
        var arr = ["Geeks", "for", "Geeks"];
     
        // Creating a string
        var str = arr.toString();
        console.log(str);
    }
    func();
</script>

Output:

Geeks,for,Geeks

Example 2: In this example, the toString() method creates a string consisting of array elements.

JavaScript




<script>
    // JavaScript to illustrate toString() method
    function func() {
        // Original array
        var arr = [2, 5, 8, 1, 4];
     
        // Creating a string
        var str = arr.toString();
        console.log(str);
    }
    func();
</script>

Output:

2,5,8,1,4

We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.

Supported Browsers: The browsers supported by JavaScript Array toString() method are listed below:

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 4 and above
  • Opera 4 and above
  • Safari 1 and above

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.


My Personal Notes arrow_drop_up
Last Updated : 14 Dec, 2022
Like Article
Save Article
Similar Reads
Related Tutorials