Convert Space Separated string to Array in JavaScript

Use the split() method.

yourString.split(" ");


Let’s say we have a string with some words separated with spaces. In many cases, it would be more comfortable to store it in the array. We just need to convert the string to the array with the split().

    var words = 'Mango Car Wallet Headphones';
    var array = words.split(" ");


Output: (4) [‘Mango’, ‘Car’, ‘Wallet’, ‘Headphones’]