Split String by Comma

To split a string by comma character in JavaScript, call split() method on the given string and pass comma delimiter string as argument in the method call.

The expression to split a string str by comma delimiter is

str.split(',');

Example

In the following example, we take a string in str, split the string by comma delimiter ',', and display the splits array in pre#output.

index.html

ADVERTISEMENT

Conclusion

In this JavaScript Tutorial, we learned how to split the given string by comma delimiter using String.split() method, with example program.