const array = ['one','two','three'] console.log(array.toString()) //Output: "one,two,three"
This method converts the array and return the string with commas as the separator between the elements.
You can also convert mix array to string. Here is an example with an mix array.
const array = ['one','two','three', 4, 5, 6] console.log(array.toString()) //output : "one,two,three,4,5,6"
toString() method convert each element of different data-type into a string.
If you don't want to convert the array to string with the comma separator then you can use the
Just pass the required separator as a parameter in
const array = ['one','two','three'] console.log(array.join('+')) //output : "one+two+three" console.log(array.join('/')) //output : "one/two/three" console.log(array.join(' ')) //output : "one two three"
Now, if you pass an empty string as a separator then it will return a string without any comma separator.
const array = ['one','two','three'] console.log(array.join('')) //output: onetwothree
This article is how to sort an array of string with non-ASCII characters. Using localeCompare() we can sort mixed array with non-ascii characters.