19
rated 0 times
[
23]
[
4]
/ answers: 1 / hits: 60767
/ 12 Years ago, thu, october 11, 2012, 12:00:00
I don't understand this behaviour:
var string = 'a,b,c,d,e:10.';
var array = string.split ('.');
I expect this:
console.log (array); // ['a,b,c,d,e:10']
console.log (array.length); // 1
but I get this:
console.log (array); // ['a,b,c,d,e:10', '']
console.log (array.length); // 2
Why two elements are returned instead of one? How does split
work?
Is there another way to do this?
More From » arrays