I am trying to explode an string using javascript to pick searchterms, whitespace-separated. However I get empty array elements if a searchterm is ended by a whitespace, as
You could simply match all non-space character sequences:
str.match(/[^ ]+/g)