Split string by comma in JavaScript
In this tutorial, you are given a string, and learn how to split this string by comma separator.
Solution
To split string str
by comma in JavaScript, call split() function on the string, and pass comma character as argument to split() function
str.split(',')
Example
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(',');
console.log(output);