Skip to main content
reflow
Source Link
mykhal
  • 20k
  • 11
  • 84
  • 84

array.length method is not a count of array's items, but the highest index. even when the item was set to undefined. this behavior is hardly distinguishable from a language design bug.

var a = [];
a.length;   // === 0
a[10];      // === undefined
a[10] = undefined;
a.length;   // === 11
a.pop();    // === undefined
a.length;   // === 10

this behavior is hardly distinguishable from a language design bug..

array.length method is not a count of array's items, but the highest index. even when the item was set to undefined. this behavior is hardly distinguishable from a language design bug.

var a = [];
a.length;   // === 0
a[10];      // === undefined
a[10] = undefined;
a.length;   // === 11
a.pop();    // === undefined
a.length;   // === 10

array.length method is not a count of array's items, but the highest index. even when the item was set to undefined

var a = [];
a.length;   // === 0
a[10];      // === undefined
a[10] = undefined;
a.length;   // === 11
a.pop();    // === undefined
a.length;   // === 10

this behavior is hardly distinguishable from a language design bug..

Source Link
mykhal
  • 20k
  • 11
  • 84
  • 84

array.length method is not a count of array's items, but the highest index. even when the item was set to undefined. this behavior is hardly distinguishable from a language design bug.

var a = [];
a.length;   // === 0
a[10];      // === undefined
a[10] = undefined;
a.length;   // === 11
a.pop();    // === undefined
a.length;   // === 10
Post Made Community Wiki by mykhal