W3docs

How to Convert a Comma-Separated String into Array

Read this tutorial and learn information about the JavaScript built-in split() method which is called for converting a comma-separated string in an array.

There is a built-in JavaScript method which you can use and convert a comma-separated string into an array.

The split() method splits a string using a specific separator such as comma (,).

Use a comma separator in the first argument of the split method if you want to split it by comma:

Javascript arrays split method

javascript— editable

Use the limit parameter to split a string into an array and also get the individual name.

Javascript arrays split method

javascript— editable

If you pass an empty string, each character will be splitted and converted into an array:

Javascript arrays split method

javascript— editable

The split() method

The <kbd class="highlighted">split()</kbd> method is called to split a string into an array of substrings and to return a new array. The <kbd class="highlighted">split()</kbd> method cuts a string into an ordered set of substrings and puts these substrings into an array returning a new array.