+ 1
JavaScript: Why does arr length is 42?
var a = []; a[0] = 0; a.push(1); a[41] = 41; console.log(a.length); //42 // console.log(a) outputs only three elements: [0,1,41] How does js count array length?
2 ответов
+ 2
it start from index 0. so count the 0 too
+ 1
Because index start from 0 and last index is 41 that's why length is 42.