Favorites

JavaScript Array.prototype.at() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Array.prototype.at()
JavaScript Array Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The at() method returns the element at a given index, and accepts negative numbers to count back from the end of the array.

Description

The at() method of Array instances returns the element at an index. It works like square-bracket access, arr[i], with one difference: negative indexes count from the end, so arr.at(-1) is the last element and arr.at(-2) the one before it.

It is a shorter, clearer replacement for arr[arr.length - 1]. Indexes outside the array return undefined.

at() also exists on strings and typed arrays, so the same pattern works for all of them. Non-integer indexes are truncated, so at(1.7) is the same as at(1). Like bracket access, it doesn't change the array, and it's a read-only operation; to replace an element at a negative index without mutating the array, use with().

Syntax

array.at(index)

Parameters

  • indexThe position of the element. Negative numbers count back from the end, so -1 is the last element.

Return Value

The element at that position, or undefined if the index is out of range.

Example

const items = ['first', 'middle', 'last'];
console.log(items.at(0));
console.log(items.at(-1));
console.log(items.at(-2));
console.log(items.at(10));

Browser Support

The following information will show you the current browser support for the Array.prototype.at() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee