Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Array-like objects

An array-like object exposes a length and indexed properties, but need not be an array or an iterable. Learn what length means and how Array.from() creates an array from this structure.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

const arrayLike = { 0: value0, 1: value1, length: 2 };

An array-like object typically has a length property and elements accessible at indices from 0 to length - 1. This is not a separate class or a guarantee that the object is an array. One example is arguments inside an ordinary function; it does not inherit array methods such as map().

Array-like length property describes the role of length on such an object. Array methods normalize it to an integer between 0 and 2 ** 53 - 1. Not every index must exist. On an ordinary object, adding an index does not automatically update length, and reducing length does not delete properties — unlike an array.

Being array-like and being iterable are separate characteristics. A length property alone does not provide the [Symbol.iterator]() method required by for...of and [...value] syntax. Array.from() uses the iterator method if it is callable. It reads length and the indexed properties only if the Symbol.iterator property is absent or its value is undefined or null. If Symbol.iterator has any other non-callable value, such as false, Array.from() throws a TypeError before reading length. When reading by index, a missing index becomes an existing element whose value is undefined in the new array.

Many array methods can be borrowed, for example Array.prototype.map.call(arrayLike, fn), but not every method is generic. The conversion with Array.from() itself uses only ECMAScript and does not require DOM APIs. To display the results, the example uses console.log, which is provided by the host environment. Working in Node.js does not establish browser API support.

Examples

const arrayLike = { 0: "A", 2: "C", length: 3 };
const values = Array.from(arrayLike);

console.log(Array.isArray(arrayLike));
console.log(typeof arrayLike[Symbol.iterator]);
console.log(values.length);
console.log(values[0], values[1], values[2]);
console.log(1 in values);

Result

false
undefined
3
A undefined C
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources