JavaScript: Array.prototype.length

By Xah Lee. Date: . Last updated: .
arrayX.length
The value is number of elements of array. Note, each array has its own property "length" and Property Attribute configurable false, so you cannot delete it.
console.log( [3,4].length === 2); // true

Array length can be set. If you set it, the array will be lengthened (becomes Sparse Array) or shortened (tail elements removed).

Length is Own Property

const arr = [3, 4, 5];

console.log(
  arr.hasOwnProperty("length"),
); //

Length Property Cannot be Deleted

the length property of array has configurable attribute false. [see Property Attributes]

// the length property of array has configurable attribute false
console.log(Object.getOwnPropertyDescriptor([3, 4], "length"));
// { value: 2, writable: true, enumerable: false, configurable: false }
// indexes of array are enumerable
console.log(Object.getOwnPropertyDescriptor([3, 4], "0"));
// { value: 3, writable: true, enumerable: true, configurable: true }
JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Array

prototype