【发布时间】:2016-03-13 22:49:49
【问题描述】:
为什么String.prototype.split在被分割的字符串是串联的情况下返回完整的字符串?
// Single line
var x = "foo,bar,boo,far".split(",");
// Concatenation
var y = "foo,bar," +
"boo,far".split(",");
// Output
document.write("<pre>");
document.write(x + " :" + typeof x + "\n");
document.write(y + " :" + typeof y + "\n");
document.write("</pre>");
在我的实际代码中,字符串很长,并在最后以.split(",") 连接多行。
那么为什么这会产生完整的字符串而不是预期的数组呢?
【问题讨论】:
标签: javascript string split concatenation