String split returns an array with two elements instead of one

后端 未结 12 1568
渐次进展
渐次进展 2020-12-03 06:15

I don\'t understand this behaviour:

var string = \'a,b,c,d,e:10.\';
var array = string.split (\'.\');

I expect this:

consol         


        
12条回答
  •  星月不相逢
    2020-12-03 07:02

    You have a string with one "." in it and when you use string.split('.') you receive array containing first element with the string content before "." character and the second element with the content of the string after the "." - which is in this case empty string.

    So, this behavior is normal. What did you want to achieve by using this string.split?

提交回复
热议问题