var words = "hello world".split(" "); var word1 = words[0]; var word2 = words[1];
It is just as long, but much more readable. To answer your question, I think the above is easy enough without getting into a regular expression.
Update
JavaScript, unfortunately, does not have concurrent functions like Ruby. I.e
var word1, word2 = phrase.split(" "); will not set word1 and word2 to words[0] and words[1] respectively.
Instead, it will install both word1 and word2 in the returned array ["hello", "world"].
Now you can use the returned array instead of explicitly setting the results to variables and accessing them by index. This is especially useful to avoid creating a large number of variables when the string is quite long.
Mcstretch
source share