How to split a string into an array in JavaScript?

Question:

There is an elegant way to split a string into an array based on the example:

var x = "FAT* FAT32*";

And that it results in something like this:

x[0] = "FAT*";
x[1] = "FAT32*";

Answer:

Yes there is, it's using split() .

var x = "FAT* FAT32*";
var array = x.split(" ");
console.log(array[0]);
console.log(array[1]);

I put it on GitHub for future reference .

Scroll to Top