Yes, but it's easier overall to do as he requested, so that he doesn't have to worry about any empty elements.
Trivial:
Code:
var s = " test1 test2 test3 test4 ";
var arr = s.replace(/\s+/g, " ").replace(/(^\s|\s$)/g,"").split(" ");
First, reduce all multiple spaces to one space. Then trim the space (if any) off the front and back of the string. Then split on space.