Array.prototype.entries()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since May 2018.
El método entries()
retorna un nuevo objeto Array Iterator
que contiene los pares clave/valor para cada índice de la matriz.
Pruébalo
const array1 = ["a", "b", "c"];
const iterator1 = array1.entries();
console.log(iterator1.next().value);
// Expected output: Array [0, "a"]
console.log(iterator1.next().value);
// Expected output: Array [1, "b"]
Sintaxis
arr.entries()
Valor de retorno
Un nuevo objeto iterador Array
.
Ejemplos
Usando un bucle for…of
js
var a = ["a", "b", "c"];
var iterator = a.entries();
for (let e of iterator) {
console.log(e);
}
// [0, 'a']
// [1, 'b']
// [2, 'c']
Especificaciones
Specification |
---|
ECMAScript® 2025 Language Specification # sec-array.prototype.entries |
Compatibilidad con navegadores
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
entries |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.