String split returns an array with two elements instead of one

后端 未结 12 1543
渐次进展
渐次进展 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 06:54

    Because your string is composed of 2 part :

    1 : a,b,c,d,e:10

    2 : empty

    If you try without the dot at the end :

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

    output is :

    ["a,b,c:10"]
    

提交回复
热议问题