JavaScript Code

How to split string by comma in JavaScript?

Split string by comma in JavaScript

In this tutorial, you are given a string, and learn how to split this string by comma separator.


To split string str by comma in JavaScript, call split() function on the string, and pass comma character as argument to split() function



1. In the following program, we split the given string value in name by comma separator.

let name = 'apple,banana,cherry';
let output = name.split(',');