chr*_*ude 0 javascript arrays string
我有一个空格分隔的字符串,我想做成一个数组.我正在使用该.split(' ')方法来执行此操作.结果数组中是否包含这些空格?例如,如果我的字符串是,"joe walked down the street"并且我在其上执行了该方法,那么数组是否会像这样["joe", "walked", "down", "the", "street"]或者它看起来像这样["joe ", "walked ", "down ", "the ", "street "]?
不,它不会有空间.它看起来像这样:
["joe", "walked", "down", "the", "street"]
Run Code Online (Sandbox Code Playgroud)
由于空间有点难以看到,让我们看一个具有相同效果的更明显的例子:
var str = "joe...walked...down...the...street";
var arr = str.split("...");
alert(arr); //["joe", "walked", "down", "the", "street"]
Run Code Online (Sandbox Code Playgroud)