Let’s take an example.
// app.js let arr = ['krunal', 'ankit', 'rushabh', 'dhaval']; console.log(arr.toString());
The output is the following.
So, that means it has returned the comma-separated values.
The returned string will separate the elements in the array with commas.
Instead, it knows how to concatenate the strings so that it will convert everything into a string.
Convert Array of Arrays to String
// 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 a comma as well.
See the below output.
That’s it for this tutorial.