Widely availableSupported across all major browsers. Safe to use in production.

Overview

Arrays are iterable with the for … of statement and enumerable with the methods entries(), keys(), and values().

Browser support

Feature Desktop Mobile
Chrome
Edge
Firefox
Safari
Chrome Android
Safari iOS
38
12
36
10
38
10
Built-in object

The entries() method of Array instances returns a new array iterator object that contains the key/value pairs for each index in the array.

38
12
28
8
38
8

The keys() method of Array instances returns a new array iterator object that contains the keys for each index in the array.

38
12
28
8
38
8

The values() method of Array instances returns a new array iterator object that iterates the value of each item in the array.

66
14
60
9
66
9
1+Supported (version) Not supported Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Notes 6 item(s)
Removed
  • This feature was removed in a later browser version (36)
  • This feature was removed in a later browser version (27)
Implementation note
  • Previously available under a different name: @@iterator (27)
  • A placeholder property named `@@iterator` is used.
  • Previously available under a different name: iterator (17)
  • A placeholder property named `iterator` is used.

Syntax

JAVASCRIPT
const arr = ['a', 'b', 'c'];

for (const [i, v] of arr.entries()) {
  console.log(i, v); // 0 'a', 1 'b', 2 'c'
}

[...arr.keys()];   // [0, 1, 2]
[...arr.values()]; // ['a', 'b', 'c']

Live demo

ki- and Value Read with entries()

For...of loop in, index and value simultaneous to getout..

PreviewFullscreen

index. onlyread with keys()

Array. all. index(ki-) itere-ta and read..

PreviewFullscreen

Value. onlyread with values()

Array. Elementvalue order to getoutitere-ta read..

PreviewFullscreen

Use cases

  • Using Array iterators

    Arrays are iterable with the for … of statement and enumerable with the methods entries(), keys(), and values().

Cautions

  • No specific concerns. Stable across all major browsers.

Accessibility

  • When updating the DOM dynamically, announce important changes to assistive technology with aria-live regions.

Powered by web-features