Let’s take an example.
// app.js let arr = ['krunal', 'ankit', 'rushabh', 'dhaval']; console.log(arr.toString());
The output is following.
So, that means it has returned the comma separated values.
The returned string will separate the elements in the array with commas.
Convert Array of Arrays to String
We can also convert an array of arrays into a String. Let’s see the following example.
// app.js let arr = [['krunal', 'ankit', ['hello']], ['rushabh', 'dhaval']]; console.log(arr.toString());
The output will be a single string with all the items comma separated. Notice that also, subarrays are separated by comma as well.
See the below output.