Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Array.prototype.at: an element by relative index

The at method reads an array element and lets a negative index count from the end without manually using length.

Version: ECMAScript 2026 draft; example target: Node.js 24.22.2

Syntax

array.at(index)

array.at(index) converts index to an integer by truncating its fractional part. A non-negative index counts from the start; a negative one is relative to array.length, so -1 means the last element. The method is generic for array-like receivers and does not mutate them.

When the computed index is out of range, it returns undefined without reading the property. A sparse hole also produces undefined, so the result alone cannot distinguish a hole from an explicit value. NaN behaves like index 0, while Infinity is out of range.

A null or undefined receiver throws TypeError. Unlike array[-1], which looks for a property named "-1", at(-1) performs end-relative indexing. The example covers negative, out-of-range, and fractional indexes.

Examples

const values = ["first", "middle", "last"];
console.log(values.at(-1));
console.log(values.at(-4));
console.log(values.at(1.9));

Result

last
undefined
middle

Sources