JavaScript Array at() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

Array.prototype.at(index) returns one element by index. Positive indexes count from the start; negative indexes count from the end. It is read-only (ES2022) and never mutates the array.

Remember
array.at(index)

at(0)   → first element
at(-1)  → last element
at(-2)  → second-to-last

out of range → undefined
array[-1]    → undefined  (not the last item!)

Syntax

Call array.at. Start with this line.

JavaScript
array.at(index)
CallWhat it does
array.at(index)Primary signature.
array.at(...)Call with the arguments your case needs.

Built into JavaScript. Call at(...) on an array instance — no import required.

Library declarations
JavaScript
array.at(index)

Parameters

ParameterDescription
indexRequired. Position; negative counts from the end

Return Value

Return ValueDescription
*The value returned by array.at().

JavaScript Examples

Example 1 — Positive Indexes

Read the first and third items with at(0) and at(2).

JavaScript
const languages = ["JavaScript", "Python", "Java", "C++", "Ruby"];

console.log(languages.at(0));  // "JavaScript"
console.log(languages.at(2));  // "Java"
Try It Yourself

How It Works

  1. Build the array. Five language names; indexes run 0 … 4.
  2. Read the first slot. at(0) returns "JavaScript" — same idea as languages[0].
  3. Skip ahead. at(2) lands on the third item → "Java".
  4. No side effects. The array is unchanged; at only reads.

Example 2 — Negative Indexes from the End

Use at(-1) for the last item and at(-2) for the one before it.

JavaScript
const languages = ["JavaScript", "Python", "Java", "C++", "Ruby"];

console.log(languages.at(-1));  // "Ruby"
console.log(languages.at(-2));  // "C++"
Try It Yourself

How It Works

  1. Start from the end. Negative indexes add length first.
  2. Last item. -1 + 5 = 4 → "Ruby".
  3. One step earlier. -2 + 5 = 3 → "C++".
  4. Why it helps. You avoid writing languages[languages.length - 1].

Example 3 — at(-1) vs array[-1]

Bracket notation does not support Python-style negative indexes in JavaScript.

JavaScript
const languages = ["JavaScript", "Python", "Java", "C++", "Ruby"];

console.log(languages.at(-1));              // "Ruby"
console.log(languages[-1]);                 // undefined
console.log(languages[languages.length - 1]); // "Ruby"
Try It Yourself

How It Works

  1. Use at for relative access. at(-1) resolves to the last slot → "Ruby".
  2. Brackets look up a key. languages[-1] means property "-1", which does not exist → undefined.
  3. Legacy pattern still works. length - 1 is the pre-ES2022 way to get the last item.
  4. Rule of thumb. Want the last item? Prefer at(-1), never arr[-1].

Browser & Runtime Support

Array.prototype.at() is part of ES2022. Evergreen browsers shipped it in 2021–2022; Node.js added it in version 16.6.

✓ Baseline · ES2022

Array.prototype.at()

Supported in Chrome 92+, Firefox 90+, Safari 15.4+, Edge 92+, and Node 16.6+. Not available in Internet Explorer.

95% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Array.at() Excellent

Bottom line: Safe for modern web apps and current Node LTS releases. For IE11 or very old browsers, feature-detect with if ("at" in Array.prototype) and fall back to arr[arr.length - 1] or a small polyfill.

Frequently Asked Questions

at(index) returns the element at that position. Positive indexes count from the start (0 is first). Negative indexes count from the end (−1 is last). It does not change the array.
For non-negative indexes they match on dense arrays. The big difference is negative indexing: array.at(−1) returns the last element, but array[−1] is undefined because −1 is treated as a string property key, not a relative offset.
It returns undefined when the resolved index is before 0 or at/after length—same as a missing slot with brackets, and it never throws.
Yes. String.prototype.at uses the same negative-index rules for characters (UTF-16 code units). See the String at() tutorial for details.
at() is ES2022. It works in Chrome 92+, Firefox 90+, Safari 15.4+, Edge 92+, and Node.js 16.6+. For older targets, use array[array.length − 1] or a small polyfill.
Prefer at() when you need the last item (at(−1)), relative offsets from the end, or clearer intent. Brackets are fine for simple forward indexes like arr[0].

Next: concat()

Learn how to combine multiple arrays into one without mutating the originals.

concat() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful