JavaScript Array entries() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

Array.prototype.entries() returns an iterator of [index, value] pairs for every slot in the array. It does not mutate the array and does not build a full result array unless you ask for one.

Remember
array.entries()

yields → [0, first], [1, second], …

use with: for...of  |  [...arr.entries()]
siblings: keys() · values()

read-only · lazy iterator · ES2015

Syntax

Call array.entries. Start with this line.

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

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

Library declarations
JavaScript
array.entries()

Parameters

ParameterDescription
ArrayRequired. Source of indexes and values
entries()Required. Creates the iterator
ConsumerRequired. for...of, spread, or .next()

Return Value

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

JavaScript Examples

Example 1 — Basic for...of Loop

Call entries() and log each pair as the iterator advances.

JavaScript
const colors = ["red", "green", "blue"];
const iterator = colors.entries();

for (const entry of iterator) {
  console.log(entry);
}
// [0, "red"]
// [1, "green"]
// [2, "blue"]
Try It Yourself

How It Works

  1. Build the array. Three color strings at indexes 0, 1, and 2.
  2. Create the iterator. entries() returns a lazy walker — not a new array yet.
  3. Pull each pair. for...of asks for the next [index, value] until done.
  4. No mutation. colors is unchanged after the loop.

Example 2 — Destructure Index and Value

Split each pair into named variables in the loop header.

JavaScript
const colors = ["red", "green", "blue"];

for (const [index, value] of colors.entries()) {
  console.log("Index: " + index + ", Value: " + value);
}
// Index: 0, Value: red
// Index: 1, Value: green
// Index: 2, Value: blue
Try It Yourself

How It Works

  1. Each yield is a tiny array. Shape is always [index, value].
  2. Destructure in the header. [index, value] unpacks that pair every step.
  3. Use both sides. Print or process index and value without entry[0] / entry[1].
  4. Idiomatic style. This is the usual readable pattern for entries().

Example 3 — Spread Pairs into an Array

Turn the iterator into a real array of pairs with the spread operator.

JavaScript
const colors = ["red", "green", "blue"];

const pairs = [...colors.entries()];

console.log(pairs);
// [[0, "red"], [1, "green"], [2, "blue"]]
console.log(Array.isArray(pairs)); // true
Try It Yourself

How It Works

  1. Start from the iterator. colors.entries() is still lazy until consumed.
  2. Spread exhausts it. ... pulls every pair into a new array.
  3. Get a real array. pairs supports map, filter, and JSON.stringify.
  4. Trade-off. You pay memory for the full list — fine for small arrays; prefer a loop for huge ones.

Browser & Runtime Support

Array.prototype.entries() was added in ES2015 (ES6) with the iterator protocol (keys, values, entries).

✓ Baseline · ES2015

Array.prototype.entries()

Supported in Chrome 38+, Firefox 28+, Safari 8+, Edge 12+, and Node.js 0.12+. Not available in Internet Explorer.

97% 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.entries() Excellent

Bottom line: Safe for modern apps. For IE11, use a classic indexed for loop or a polyfill that yields [i, arr[i]] pairs.

Frequently Asked Questions

entries() returns a new Array Iterator. Each step yields a two-element array [index, value] for the next slot, from index 0 through length − 1.
No. It only creates an iterator over existing data. Looping or spreading does not change the array.
Each yield is a pair like [0, "red"] — numeric index first, element value second.
forEach() runs a callback immediately and returns undefined. entries() returns a lazy iterator you can use with for...of, spread into an array, or pass to Object.fromEntries().
Use entries() when you need both index and value. Use keys() for indexes only and values() for elements only.
entries() is ES2015 (ES6). All modern browsers and Node.js support it; Internet Explorer does not.

Next: every()

Learn how to test whether every element passes a condition.

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.

9 people found this page helpful