C
Christopher Benson-Manica
Why does ''.split(',') yield an array with length 1 rather than an
array with length 0?
array with length 0?
Christopher said:Why does ''.split(',') yield an array with length 1 rather than an
array with length 0?
Fred Oz said:Because the first element of the array will be everything up to
the first ','. You have created an array with one element that
contains nothing. It is equivalent to:
Fred Oz said:Christopher said:Why does ''.split(',') yield an array with length 1 rather than an
array with length 0?
Because the first element of the array will be everything up to
the first ','. You have created an array with one element that
contains nothing. It is equivalent to:
var newArray = [,];
Which has a length of 1, but it contains nothing.
Some examples:
alert( ''.split(',').length) // 1
var z = []; alert(z.length) // 0
var z = [,]; alert(z.length) // 1
Why does ''.split(',') yield an array with length 1 rather than an
array with length 0?
Chris said:var z = [,]; alert(z.length) // 1
returns 2 for me, is it that there's a space before and after the comma?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.