Array.prototype.values()
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.
La méthode values()
renvoie un nouvel objet Array Iterator
qui contient les valeurs pour chaque indice du tableau. Cette méthode est l'implémentation par défaut de Array.prototype[Symbol.Iterator]
.
Exemple interactif
const array1 = ["a", "b", "c"];
const iterator = array1.values();
for (const value of iterator) {
console.log(value);
}
// Expected output: "a"
// Expected output: "b"
// Expected output: "c"
js
var a = ["t", "i", "t", "o", "u"];
var iterateur = a.values();
console.log(iterateur.next().value); // t
console.log(iterateur.next().value); // i
console.log(iterateur.next().value); // t
console.log(iterateur.next().value); // o
console.log(iterateur.next().value); // u
Syntaxe
js
array.values();
Valeur de retour
Un nouvel objet itérateur sur Array
.
Exemples
Itérer avec une boucle for...of
js
var arr = ["w", "y", "k", "o", "p"];
var eArr = arr.values();
// votre navigateur doit supporter les boucles for..of
// et les variables définies avec let
for (let lettre of eArr) {
console.log(lettre);
}
Itérer avec next()
js
var arr = ["w", "y", "k", "o", "p"];
var eArr = arr.values();
console.log(eArr.next().value); // w
console.log(eArr.next().value); // y
console.log(eArr.next().value); // k
console.log(eArr.next().value); // o
console.log(eArr.next().value); // p
Spécifications
Specification |
---|
ECMAScript® 2025 Language Specification # sec-array.prototype.values |
Compatibilité des navigateurs
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
values |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Has more compatibility info.
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.