How do I convert string to array in JavaScript?

To convert a string to an array in JavaScript, you can use the string.split(separator, limit), Array.from(string) methods and the spread ("...") operator. The split() method is used to split the specified string into an array of strings using "separator" as the delimiter. The second parameter determines how many times to divide the matching value. The string.split() method returns a new array without changing the original string. The from() method converts and returns a new array from any object or iterable object; if you pass a string to the method, it will be converted to a character array. You can also use the spread operator ("..."), which is the modern way to convert a string to an array in ES6. In this JavaScript string to array conversion example, we use the split() method. Below you can see more examples of converting a string to array JavaScript with a detailed description of each method. Click Execute to run the JavaScript String to Array Example online and see the result.
Loading...