JS: Array.prototype.length

By Xah Lee. Date: . Last updated: .


The length property of an Array instance is a data property whose value is always numerically greater than the name of every configurable own property whose name is an array index.

Typically, the value is number of elements of array. (provided you didn't set length, and didn't use delete operator to delete array elements, etc.)

[see JS: Delete operator]

const ar = [3,4];
console.log ( ar.length ); // 2

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

[see JS: Sparse Array]

[see JS: Understand JS Array]

JS Array

  1. Understand JS Array
  2. Create Array
  3. Sparse Array
  4. Array-Like Object
  5. Array How-To

Like it? Help me by telling your friends. Or, Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials