JavaScript TypedArray entries() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
ES2015

Definition

typedArray.entries() returns a new iterator of [index, value] pairs. Each step gives a small normal array with two items: the index first, then the element stored at that index. It is the easiest way to get both the position and the value in a for...of loop, usually with destructuring: for (const [i, v] of ta.entries()).

Remember
typedArray.entries()   → iterator of [index, value]

new Int8Array([5, -6]).entries()   → [0, 5], [1, -6]

for (const [i, v] of ta.entries()) { ... }
Array.from(ta.entries())     → [[0, 5], [1, -6]]
new Map(ta.entries())        → Map { 0 => 5, 1 => -6 }

Syntax

entries() takes no arguments. Call it on any typed array.

JavaScript
typedArray.entries()
CallWhat it does
ta.entries()Get an iterator of [index, value] pairs.
for (const [i, v] of ta.entries())Loop with the index and the value in two named variables.
Array.from(ta.entries())Collect all pairs into an array of two-item arrays.

Built into JavaScript since ES2015 on all 11 typed array types. The index is always a number; the value has the element type (a BigInt on BigInt64Array and BigUint64Array).

Library declarations
JavaScript
TypedArray.prototype.entries()   // returns an Array Iterator

// iterator.next() -> { value: [index, element], done: false }
// after the last element -> { value: undefined, done: true }
// each pair is a new, normal two-item Array

Parameters

ParameterDescription
(none)entries() has no parameters. Extra arguments are ignored.

Return Value

Return ValueDescription
Array IteratorA new iterator object. Each next() call returns { value: [index, element], done }. The pair is a regular Array, not a typed array.

JavaScript Examples

Example 1 — Destructure [index, value] in a Loop

Daily step counts sit in a Uint16Array. Destructuring each pair gives two clear variable names.

JavaScript
const steps = new Uint16Array([5200, 8100, 3900]);

for (const [day, count] of steps.entries()) {
  console.log('Day ' + day + ' -> ' + count + ' steps');
}
Try It Yourself

How It Works

  1. Each turn yields a pair. steps.entries() produces [0, 5200], [1, 8100], and [2, 3900], one pair per loop turn.
  2. Destructuring names both parts. The pattern [day, count] puts the first item of the pair in day and the second in count, so there is no pair[0] noise.
  3. Indexes still start at zero. The printed day numbers are the raw indexes 0, 1, and 2, showing that entries() counts positions from 0 like every typed array.

Example 2 — Remember Where the Maximum Was

To report both the largest reading and its position, we keep the best pair seen so far. The first maximum wins a tie.

JavaScript
const readings = new Float64Array([3.5, 9.25, 9.25, 1]);
let best = [-1, -Infinity];

for (const entry of readings.entries()) {
  if (entry[1] > best[1]) best = entry;
}

console.log('max ' + best[1] + ' at index ' + best[0]);  // max 9.25 at index 1
console.log(Array.isArray(best));                         // true
console.log(best.length);                                 // 2
Try It Yourself

How It Works

  1. Start below every reading. The starting pair [-1, -Infinity] loses to any real value, so the first entry always replaces it.
  2. A strict comparison keeps the first tie. Index 2 also holds 9.25, but 9.25 > 9.25 is false, so the pair from index 1 stays the winner.
  3. The winner is a plain pair. The kept entry is a normal Array with two items, which is why Array.isArray(best) is true and its length is 2.

Example 3 — Turn the Pairs Into JSON and a Map

The pairs from entries() have the exact shape that new Map() expects, and Array.from() makes them printable.

JavaScript
const codes = new Int8Array([-2, 0, 7]);

const pairs = Array.from(codes.entries());
console.log(JSON.stringify(pairs));       // [[0,-2],[1,0],[2,7]]
console.log(JSON.stringify(codes.entries()));  // {}

const byIndex = new Map(codes.entries());
console.log(byIndex.get(2));              // 7
console.log(byIndex.size);                // 3
Try It Yourself

How It Works

  1. Collect the pairs first. Array.from(codes.entries()) turns the iterator into an array of three pairs, and JSON.stringify prints it in full.
  2. An iterator alone prints as {}. Passing the iterator straight to JSON.stringify shows {}, because the iterator object has no data properties of its own.
  3. Pairs feed a Map directly. new Map(codes.entries()) uses each index as a key and each element as its value, so get(2) returns 7 and the Map holds 3 entries.

Browser & Runtime Support

TypedArray.prototype.entries() is part of ES2015 (ES6), together with typed arrays, iterators, and destructuring.

✓ Baseline · ES2015

TypedArray.prototype.entries()

Supported in every modern browser, plus Node.js, Deno, and Bun.

98% Modern browser support
Google Chrome All modern versions
Full support
Mozilla Firefox All modern versions
Full support
Apple Safari All modern versions
Full support
Microsoft Edge All modern versions
Full support
Node.js All current releases
Supported
Deno All releases
Supported
Internet Explorer IE 10 and 11 have typed arrays, but not this method
Not supported
entries() Excellent

Bottom line: Safe everywhere modern JavaScript runs. In Internet Explorer 10 and 11, which have typed arrays but no iterators, use a plain for loop with an index instead.

Frequently Asked Questions

An iterator of [index, value] pairs. Each pair is a normal two-item Array: the index comes first, then the element at that index.
No. Each pair is a regular Array. The index is a number and the value has the element type, for example a BigInt on a BigInt64Array, so changing the pair does not change the typed array.
Use for (const [i, v] of ta.entries()). Another option is ta.forEach((value, index) => ...), which passes the value first and the index second.
The iterator object has no data properties of its own, so JSON sees an empty object. Convert it first: JSON.stringify(Array.from(ta.entries())).
Yes. new Map(ta.entries()) creates a Map whose keys are the indexes and whose values are the elements, because each pair already has the [key, value] shape a Map needs.

Next: every()

Check whether every element of a typed array passes a test.

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