From 39f2114f9797eb51994966c6bb8ff1814c9a4da8 Mon Sep 17 00:00:00 2001 From: Florian Merz Date: Thu, 11 Feb 2021 12:36:08 +0100 Subject: unslug fr: move --- .../global_objects/array/entries/index.html | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 files/fr/web/javascript/reference/global_objects/array/entries/index.html (limited to 'files/fr/web/javascript/reference/global_objects/array/entries') diff --git a/files/fr/web/javascript/reference/global_objects/array/entries/index.html b/files/fr/web/javascript/reference/global_objects/array/entries/index.html new file mode 100644 index 0000000000..127cec9f99 --- /dev/null +++ b/files/fr/web/javascript/reference/global_objects/array/entries/index.html @@ -0,0 +1,97 @@ +--- +title: Array.prototype.entries() +slug: Web/JavaScript/Reference/Objets_globaux/Array/entries +tags: + - Array + - ECMAScript 2015 + - Iterator + - JavaScript + - Méthode + - Prototype +translation_of: Web/JavaScript/Reference/Global_Objects/Array/entries +--- +
{{JSRef}}
+ +

La méthode entries() renvoie un nouvel objet de type  Array Iterator qui contient le couple clef/valeur pour chaque éléments du tableau.

+ +
{{EmbedInteractiveExample("pages/js/array-entries.html")}}
+ + + +

Syntaxe

+ +
arr.entries()
+ +

Valeur de retour

+ +

Un nouvel objet qui est un itérateur pour {{jsxref("Array")}}.

+ +

Exemples

+ +

Parcourir un tableau avec ses index et éléments

+ +
const arr = ["a", "b", "c"];
+for (const [index, element] of arr.entries()) {
+  console.log(index, element);
+}
+// 0 "a"
+// 1 "b"
+// 2 "c"
+
+ +

Boucle for...of

+ +

On peut avoir le même résultat en utilisant une boucle for...of :

+ +
var arr = ['a', 'b', 'c'];
+var eArr = arr.entries();
+
+for (let e of eArr) {
+  console.log(e);
+}
+// [0, 'a']
+// [1, 'b']
+// [2, 'c']
+
+ +

Spécifications

+ + + + + + + + + + + + + + + + + + + +
SpécificationÉtatCommentaires
{{SpecName('ES2015', '#sec-array.prototype.entries', 'Array.prototype.entries')}}{{Spec2('ES2015')}}Définition initiale.
{{SpecName('ESDraft', '#sec-array.prototype.entries', 'Array.prototype.entries')}}{{Spec2('ESDraft')}}
+ +

Compatibilité des navigateurs

+ +
+ + +

{{Compat("javascript.builtins.Array.entries")}}

+
+ +

Voir aussi

+ + -- cgit v1.2.3-54-g00ecf