JavaScript Array entries() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Iterator

What You’ll Learn

The entries() method returns an iterator of [index, value] pairs for every element in an array. This tutorial covers syntax, five examples, destructuring, comparison with keys() and values(), and when to pick an iterator over forEach.

01

Syntax

array.entries()

02

Iterator

Lazy pairs

03

Format

[i, val]

04

for...of

Loop entries

05

Read-only

No mutation

06

ES2015

Wide support

Introduction

Arrays in JavaScript are ordered lists, but sometimes you need more than the value alone—you also need the index. The entries() method gives you both at once as a stream of two-item arrays.

It is part of the same iterator family as keys() and values(), and it works naturally with for...of loops and array destructuring.

Understanding the entries() Method

Calling array.entries() does not loop immediately. It returns a fresh Array Iterator object. Each time the iterator advances, it produces another pair: the numeric index and the element stored at that index.

For ['red', 'green', 'blue'], the iterator yields [0, 'red'], then [1, 'green'], then [2, 'blue'].

💡
Beginner Tip

Think of each entry as a mini two-column row: column one is the index, column two is the value. Destructuring makes this explicit: for (const [i, v] of arr.entries()).

📝 Syntax

General form of Array.prototype.entries:

JavaScript
array.entries()

Parameters

  • None. entries() takes no arguments.

Return value

  • A new Array Iterator object.
  • Each iterator step returns [index, value].
  • The original array is not modified.

Common patterns

  • for (const entry of arr.entries()) — loop all pairs.
  • for (const [i, v] of arr.entries()) — destructure index and value.
  • Array.from(arr.entries()) — materialize pairs into a nested array.
  • Object.fromEntries(arr.entries()) — build an object keyed by index (strings).

⚡ Quick Reference

GoalCode
Get iteratorconst it = arr.entries()
Loop with index + valuefor (const [i, v] of arr.entries())
Collect all pairs[...arr.entries()]
Mutates array?No
Each yield shape[number, any]

📋 entries() vs keys() vs values() vs forEach

Pick the tool that matches whether you need indexes, values, pairs, or immediate side effects.

entries
[index, value]

Both at once

keys
index only

0, 1, 2…

values
value only

Elements

forEach
callback now

Returns undefined

Examples Gallery

Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.

📚 Getting Started

Loop index/value pairs from the iterator.

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

entries() returns an iterator, not an array. The for...of loop pulls the next pair on each iteration until the iterator is exhausted.

Example 2 — Destructure Index and Value

Split each pair into named variables with array destructuring.

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

Each yielded item is a two-element array, so [index, value] in the loop header unpacks it cleanly. This is the idiomatic pattern for readable loops.

📈 Practical Patterns

Search, label, and collect entry pairs.

Example 3 — Enumerate Elements with Labels

Build human-readable lines that include both position and content.

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

for (const [index, value] of colors.entries()) {
  console.log(`Color at index ${index}: ${value}`);
}
// Color at index 0: red
// Color at index 1: green
// Color at index 2: blue
Try It Yourself

How It Works

When displaying lists in UI or logs, pairing index with value avoids maintaining a separate counter variable.

Example 4 — Find the First Matching Index

Stop the loop early when you locate a target value.

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

for (const [index, value] of colors.entries()) {
  if (value === target) {
    console.log(`Found ${target} at index ${index}`);
    break;
  }
}
// Found green at index 1
Try It Yourself

How It Works

For simple lookups, indexOf or findIndex is shorter. entries() shines when you need custom matching logic while keeping the index handy.

Example 5 — Collect All Pairs into an Array

Spread or Array.from materializes the iterator when you need a snapshot.

JavaScript
const scores = [88, 92, 75];

const pairs = [...scores.entries()];
console.log(pairs);
// [[0, 88], [1, 92], [2, 75]]

const lookup = Object.fromEntries(scores.entries());
console.log(lookup);
// { "0": 88, "1": 92, "2": 75 }
Try It Yourself

How It Works

Iterators are one-pass by default. Spreading consumes the iterator into a nested array you can store, map, or pass to Object.fromEntries.

🚀 Common Use Cases

  • Indexed logging — print debug output with stable positions.
  • Custom search — walk elements while tracking index for early exit.
  • Data transforms — map pairs to new structures with Array.from.
  • Object conversion — feed pairs into Object.fromEntries.
  • Parallel arrays — compare or zip when index alignment matters.
  • Teaching iterators — gentle introduction to the ES2015 iterator protocol.

🧠 How entries() Runs

1

Create iterator

entries() returns a new iterator bound to the array’s current length.

Setup
2

Advance index

Each next() (or for...of step) moves to the next numeric index.

Step
3

Yield pair

Return { value: [index, element], done: false } until the end.

Produce
4

Finish

After the last index, the iterator reports done: true. The array itself is unchanged.

📝 Notes

  • Indexes are always numbers starting at 0, even if the array has holes.
  • Holey slots still get an index; the value may be undefined.
  • Iterators do not reflect later mutations unless you create a new iterator.
  • Spreading arr.entries() consumes the iterator; call entries() again for a fresh pass.
  • Object.fromEntries(arr.entries()) produces string keys ("0", "1", …).
  • Also available on typed arrays with the same behavior.

Browser & Runtime Support

Array.prototype.entries() was added in ES2015 (ES6). It is available in all evergreen browsers and modern Node.js versions.

Baseline · ES2015

Array.prototype.entries()

Supported in Chrome 38+, Firefox 28+, Safari 7.1+, Edge 12+, and Node 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 web apps. For IE11, use a for loop with an index counter or a polyfill for iterator methods.

Conclusion

The entries() method is the clean way to walk an array when you need both position and value. Pair it with destructuring for readable loops, or spread the iterator when you need a concrete list of pairs.

For values-only iteration, values() or a plain for...of on the array may be enough—but when the index matters, entries() is the right tool.

💡 Best Practices

✅ Do

  • Destructure: for (const [i, v] of arr.entries())
  • Use findIndex or indexOf for simple searches
  • Recreate the iterator if the array changes mid-loop
  • Feature-detect for very old environments
  • Prefer entries() when index and value are both needed

❌ Don’t

  • Assume entries() returns an array—it returns an iterator
  • Reuse a consumed iterator without calling entries() again
  • Use entries() when you only need values (use values() or for...of)
  • Expect numeric object keys from Object.fromEntries
  • Forget sparse arrays may yield undefined values

Key Takeaways

Knowledge Unlocked

Five things to remember about Array.entries()

Your foundation for index/value iteration in JavaScript.

5
Core concepts
🔄 02

Iterator

Lazy pairs.

Protocol
🔢 03

Shape

[i, val]

Pair
🗃 04

Read-only

No mutation.

Safe
📋 05

vs forEach

Lazy vs eager.

Compare

❓ Frequently Asked Questions

entries() returns a new Array Iterator. Each step yields a two-element array [index, value] for the next slot in the array, from index 0 through length - 1.
No. entries() only creates an iterator over existing data. Reading or looping does not change the array.
Each yield is a pair like [0, 'red'] where the first item is the numeric index and the second is the element value at that index.
forEach() runs a callback immediately and returns undefined. entries() returns a lazy iterator you can loop with for...of, spread into an array, or pass to utilities like Object.fromEntries().
Use entries() when you need both index and value together. Use keys() for indexes only and values() for elements only. All three return iterators with the same ES2015 iterator protocol.
entries() is an ES2015 (ES6) feature. All modern browsers and Node.js support it; Internet Explorer does not.
Did you know?

A plain for...of on an array gives you values only. Adding .entries() is what upgrades the loop to yield [index, value] pairs—the same tuple shape that Map uses.

Continue to every()

Learn how to test whether every element in an array 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.

6 people found this page helpful