alert("".split(",").length)为什么会弹出1,而不是0?

数组长度不是应该是0吗?

阅读 2.3k
3 个回答

这个问题你分两步分别打个console不就知道了?干嘛一定得发上来问?

参见: https://developer.mozilla.org...

Description

When found, separator is removed from the string and the substrings are returned in an array. If separator is not found or is omitted, the array contains one element consisting of the entire string.

如果没有找到分隔符,则会返回一个只有一个元素的数组,这个数组包含了原来的字符串,就算是空字符串,也算是一个元素!

看看官方的函数说明文档,就会很清楚了

推荐问题