JS: Array.prototype.length

By Xah Lee. Date: . Last updated: .

myArray.length

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]

Reference

ECMAScript® 2016 Language Specification#sec-properties-of-array-instances-length

Array Topic

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

  1. JS: Array Object
  2. JS: Array.prototype
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth