I have a space separated string that I want to make into an array. I am using the .split(' ')
method to do this. Will the resulting array have those spaces in it? For example if my string is "joe walked down the street"
and I performed the method on it would the array look like this ["joe", "walked", "down", "the", "street"]
or will it look like this ["joe ", "walked ", "down ", "the ", "street "]
?
views:
63answers:
3
+8
A:
Nope, it would not have the spaces in there. It would look like this:
["joe", "walked", "down", "the", "street"]
Since spaces are a bit hard to see, let's take a more visible example with the same effect:
var str = "joe...walked...down...the...street";
var arr = str.split("...");
alert(arr); //["joe", "walked", "down", "the", "street"]
Nick Craver
2010-10-22 01:13:33
ok, thanks. Great!
chromedude
2010-10-22 01:14:01
+2
A:
Note that for more complicated uses of split (eg splitting on a regexp), IE's split does NOT work correctly. There is a cross-browser implementation of split that works correctly.
See http://stackoverflow.com/questions/1453521/javascript-split-doesnt-work-in-ie
Larry K
2010-10-22 02:03:14