JavaScript: Array.prototype.length
arrayX.length
-
The value is number of elements of array.
console.log([3, 4].length === 2);
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
Each array has its own property "length"
.
console.log([3, 4].hasOwnProperty("length"));
Length Property Cannot be Deleted
Each array's own property "length"
has
Property Attribute
configurable
false, so you cannot delete it.
// the length property of array has configurable attribute false console.log( Object.getOwnPropertyDescriptor( [3, 4], "length", ).configurable === false, );
// indexes of array are enumerable console.log( Object.getOwnPropertyDescriptor( [3, 4], "0", ).enumerable === true, );