鍍金池/ 問答/HTML/ alert("".split(",").

alert("".split(",").length)為什么會彈出1,而不是0?

數(shù)組長度不是應該是0嗎?

回答
編輯回答
單眼皮

圖片描述

2017年2月15日 01:05
編輯回答
風清揚

參見: 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.

如果沒有找到分隔符,則會返回一個只有一個元素的數(shù)組,這個數(shù)組包含了原來的字符串,就算是空字符串,也算是一個元素!

看看官方的函數(shù)說明文檔,就會很清楚了

2018年8月13日 17:02
編輯回答
骨殘心

這個問題你分兩步分別打個console不就知道了?干嘛一定得發(fā)上來問?

2018年5月28日 21:45