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
Fundamentals
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.
Concept
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()).
Foundation
📝 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).
Cheat Sheet
⚡ Quick Reference
Goal
Code
Get iterator
const it = arr.entries()
Loop with index + value
for (const [i, v] of arr.entries())
Collect all pairs
[...arr.entries()]
Mutates array?
No
Each yield shape
[number, any]
Compare
📋 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
Hands-On
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.
Index: 0, Value: red
Index: 1, Value: green
Index: 2, Value: blue
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
Color at index 0: red
Color at index 1: green
Color at index 2: blue
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
Also available on typed arrays with the same behavior.
Compatibility
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 ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · 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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Array.entries()
Your foundation for index/value iteration in JavaScript.
5
Core concepts
📝01
Syntax
array.entries()
API
🔄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.