javascript - When the value of String is the same as String.split('') parameter one and is not empty, the length of the split array is greater than 0?
伊谢尔伦
伊谢尔伦 2017-05-19 10:30:28
0
1
526

When the value of String is the same as String.split('') parameter 1 and is not empty, the length of the split array is 2. Use String.substr(1).split('') to split the array. The array length is 1
For example:

let a = ','
a.split(',')
//返回结果 ["",""], a.length为2
a.substr(1).split(',')
//返回结果 [""], a.length为1
a = ''
a.split('') 
//返回结果[], a.length为0
伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(1)
黄舟

You don’t understand String.prototype.substr().

a.substr(1) means: starting from index 1 (the second position) and ending at the end of the string.
So what we get here is the null character.

So split did not match and returned itself (empty string).

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template