26
rated 0 times
[
33]
[
7]
/ answers: 1 / hits: 45308
/ 13 Years ago, sat, february 4, 2012, 12:00:00
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 shown below.
What should I do instead to avoid post-processing this array and removing empty elements?
var str = searchterm1 searchterm2;
console.log(str.split( )); // [searchterm1, searchterm2]
var strb = searchterm1 ; // Note the ending whitespace
console.log(strb.split( )); // [searchterm1, ]
More From » regex