Join Elements of String Array with Comma

To join elements of a string array with comma as separator in JavaScript, call join() method on the string array and pass the comma (separator string) as argument in the method call.

The expression to join elements of a string array arr by a comma ',' is

arr.join(',');

Example

In the following example, we take a string array in arr, join the elements in the array with comma character ','as separator, and display the resulting string in pre#output.

index.html

ADVERTISEMENT

Conclusion

In this JavaScript Tutorial, we learned how to join the given string array by comma character using Array.join() method, with example program.