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
黄舟2017-05-19 10:32:28
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).