Below is the example of Array toString() method.
- Example:
<script>// JavaScript to illustrate toString() methodfunctionfunc() {// Original arrayvararr = ["Geeks","for","Geeks"];// Creating a stringvarstr = arr.toString();document.write(str);}func();</script>chevron_rightfilter_none - Output:
Geeks,for,Geeks
The arr.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.
Below examples illustrate the JavaScript Array toString() method:
- Example 1: In this example the toString() method creates a string consisting of array elements.
var arr = [2, 5, 8, 1, 4] print(arr.toString());
Output:
2,5,8,1,4
Code for the above method is provided below:
Program 1:
<script> // JavaScript to illustrate toString() method function func() { // Original array var arr = [2, 5, 8, 1, 4]; // Creating a string var str = arr.toString(); document.write(str); } func(); </script> |
Output:
2,5,8,1,4
Supported Browsers: The browsers supported by JavaScript Array toString() method are listed below:
- Google Chrome
- Microsoft Edge
- Mozilla Firefox
- Safari
- Opera
Recommended Posts:
- JavaScript | RegExp toString() Method
- JavaScript Date toString() Method
- JavaScript Boolean toString() Method
- JavaScript | Error.prototype.toString() Method
- JavaScript | BigInt.prototype.toString() Method
- TypeScript | Array toString() Method
- JavaScript | string.toString()
- JavaScript | symbol.toString()
- JavaScript | toString( ) function
- JavaScript | typedArray.toString() with Examples
- JavaScript Array pop() Method
- JavaScript Array every() Method
- JavaScript Array some() Method
- JavaScript Array map() Method
- JavaScript Array from() Method
- JavaScript | Array from() Method
- JavaScript | Array map() Method
- JavaScript Array forEach() Method
- JavaScript Array shift() Method
- JavaScript Array push() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


