← Back to release summary

Relative indexing method for Array, String, and TypedArrays

Category
JavaScript
Type
Chromium catches up
Status
Enabled by default (Chrome 92)
Intent stage
Shipped

Summary

Add a new method, named at(), to Array.prototype, String.prototype, and the TypedArray prototypes, that permit relative indexing with negative indices. ``` let arr = [1,2,3,4]; arr.at(-1); // Returns 4 ```

Motivation

Relative indexing via negative indices is a feature that enjoys popularity in other languages (e.g. Python) as well as having been requested by JS programmers.

Standards & signals

Explainers: https://github.com/tc39/proposal-relative-indexing-method

View on chromestatus.com