In this section, we will learn what the toString() method is and how to use in JavaScript.
JavaScript Arrays toString() Method
With the help of toString() method we can get a string value that contains the entire elements of an array, each separated via a comma.
Note: this method won’t change the content of the original array, however.
Array toString() Syntax:
arrays.toString()
Array toString() Method Parameters:
This method does not take an argument.
Array toString() Method Return Value:
The return value of this method is a string value that contains all the elements of the target array, each separated by a comma.
Example: convert array to String JavaScript
const arr = ["John Doe", "Omid Dehghan"]; console.log(arr.toString());
Output:
John Doe,Omid Dehghan
Example: JavaScript array into string
const arr = [1,2,3,4,5,6,7,8,9]; console.log(arr.toString());
Output:
1,2,3,4,5,6,7,8,9