JavaScript TypedArray at() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
ES2022

Definition

typedArray.at(index) returns the element at the given position. It works like ta[index], with one big bonus: a negative index counts from the end, so ta.at(-1) is the last element. If the index is outside the typed array, the result is undefined. The method arrived in ES2022, together with at() on regular arrays and strings.

Remember
typedArray.at(index)   → the element, or undefined

new Uint8Array([10, 20, 30]).at(0)    → 10
new Uint8Array([10, 20, 30]).at(-1)   → 30   (last)
new Uint8Array([10, 20, 30]).at(3)    → undefined

ta[-1]  → undefined   (NOT the last element!)

Syntax

at() takes one argument: the position. Call it on any typed array.

JavaScript
typedArray.at(index)
CallWhat it does
ta.at(0)Read the first element.
ta.at(-1)Read the last element. -2 is the one before it.
ta.at(ta.length)One past the end, so the result is undefined.

ES2022 method, available on all 11 typed array types from Int8Array to BigUint64Array. The result has the element type: a number, or a BigInt for the two BigInt arrays.

Library declarations
JavaScript
TypedArray.prototype.at(index)   // returns the element or undefined

// index >= 0     -> counts from the start
// index <  0     -> counts from the end: index + length
// out of range   -> undefined

Parameters

ParameterDescription
indexThe position to read. It is converted to a whole number (1.9 becomes 1, NaN and a missing argument become 0). A negative value counts back from the end.

Return Value

Return ValueDescription
Number, BigInt, or undefinedThe element at that position, or undefined when the index is too large or too small. Compare with Array at(), which behaves the same way.

JavaScript Examples

Example 1 — Read From the Start and From the End

Four temperatures are stored in an Int16Array. A positive index counts from the start and a negative index counts from the end.

JavaScript
const readings = new Int16Array([-12, 5, 30, 48]);

console.log(readings.at(0));   // -12
console.log(readings.at(2));   // 30
console.log(readings.at(-1));  // 48
console.log(readings.at(-4));  // -12
Try It Yourself

How It Works

  1. Zero is the front door. at(0) returns -12, the first element, and at(2) returns the third one, 30. Negative stored values come back unchanged.
  2. Minus one is the last element. at(-1) jumps to the end and returns 48, without ever writing readings.length - 1.
  3. Minus four wraps to the first. With four elements, -4 means 4 - 4 = 0, so at(-4) reaches the very first element again.

Example 2 — at() Against Bracket Notation

Bytes in a Uint8Array show the trap: square brackets cannot read from the end, and both ways give undefined when the index is too far away.

JavaScript
const bytes = new Uint8Array([10, 20, 30]);

console.log('at(-1): ' + bytes.at(-1));  // at(-1): 30
console.log('[-1]: ' + bytes[-1]);       // [-1]: undefined
console.log('at(3): ' + bytes.at(3));    // at(3): undefined
console.log('at(-4): ' + bytes.at(-4));  // at(-4): undefined
Try It Yourself

How It Works

  1. Only at() reads from the end. bytes.at(-1) gives 30, the last byte, while bytes[-1] looks for a property named "-1" and finds nothing.
  2. Too big is undefined. There are three bytes, so valid positions are 0 to 2. Position 3 is outside and at(3) answers undefined instead of throwing an error.
  3. Too negative is undefined. -4 would mean index -1 after counting from the end, which is also out of range, so no value exists there either.

Example 3 — The Index Is Turned Into a Whole Number

The argument does not have to be a clean integer. A Float32Array also shows that the element comes back in the stored single-precision form.

JavaScript
const levels = new Float32Array([0.1, 2.5, 7]);

console.log(levels.at(0));      // 0.10000000149011612
console.log(levels.at(1.9));    // 2.5
console.log(levels.at('2'));    // 7
console.log(levels.at());       // 0.10000000149011612
console.log(levels.at(-1.9));   // 7
Try It Yourself

How It Works

  1. Stored form, not typed form. The first element was written as 0.1, but a Float32Array keeps single precision, so at(0) returns 0.10000000149011612.
  2. Decimals are cut off. 1.9 loses its fraction and becomes index 1, which holds 2.5. A string such as "2" is converted to the number 2 and reads 7.
  3. Nothing means zero. With no argument the index becomes 0, so the first element comes back. -1.9 is cut to -1 and reads the last element.

Browser & Runtime Support

TypedArray.prototype.at() is part of ES2022, so it needs a recent browser or runtime.

✓ Baseline · ES2022

TypedArray.prototype.at()

Chrome 92, Firefox 90, Safari 15.4, Edge 92, and Node.js 16.6 added it.

95% Recent browsers only
Google Chrome Chrome 92 and newer
Full support
Mozilla Firefox Firefox 90 and newer
Full support
Apple Safari Safari 15.4 and newer
Full support
Microsoft Edge Edge 92 and newer
Full support
Node.js Node.js 16.6 and newer
Supported
Deno Recent versions
Supported
Internet Explorer No support
Not supported
at() Recent browsers

Bottom line: Fine for current browsers and servers. For very old environments, read the last element with ta[ta.length - 1].

Frequently Asked Questions

Use ta.at(-1). The older way is ta[ta.length - 1]. Both give the same number; at(-1) is shorter and easier to read.
Square brackets only accept valid element positions, and -1 is not one. The engine does not treat it as "count from the end". Only at() does that.
No. An index that is too large or too small just returns undefined. This is the same as bracket notation for positive indexes.
The idea is the same. The typed version works on one number type and never has holes, so the result is always a number (or BigInt), or undefined when out of range.
No. It only reads one element. To replace an element at a position without changing the original, see the with() method.

Next: copyWithin()

Copy a block of elements to another place inside the same typed array.

copyWithin() 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