You already know about the method split(), which creates an array from an input string and a delimiter string. Let's take a string of comma-separated values and split it:
var csv = 'one, two,three ,four';
csv.split(',');
["one", " two", "three ", "four"]Because the input string has some inconsistent spaces before and after the commas, the array result has spaces too. With a regular expression, we can fix this, using \s*, which means "zero or more spaces":
csv.split(/\s*,\s*/) ["one", "two", "three", "four"]
