From bf8e099b9c8b3c60d60b3712b4fc97b052c39887 Mon Sep 17 00:00:00 2001 From: julieng Date: Tue, 3 Aug 2021 08:03:23 +0200 Subject: convert content to md --- .../global_objects/array/entries/index.md | 91 +++++++++------------- 1 file changed, 38 insertions(+), 53 deletions(-) (limited to 'files/fr/web/javascript/reference/global_objects/array/entries') diff --git a/files/fr/web/javascript/reference/global_objects/array/entries/index.md b/files/fr/web/javascript/reference/global_objects/array/entries/index.md index 5ab8acec51..9bfa9f7ca7 100644 --- a/files/fr/web/javascript/reference/global_objects/array/entries/index.md +++ b/files/fr/web/javascript/reference/global_objects/array/entries/index.md @@ -11,38 +11,40 @@ tags: translation_of: Web/JavaScript/Reference/Global_Objects/Array/entries original_slug: Web/JavaScript/Reference/Objets_globaux/Array/entries --- -
{{JSRef}}
+{{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.

+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")}}
+{{EmbedInteractiveExample("pages/js/array-entries.html")}} -

Syntaxe

+## Syntaxe -
arr.entries()
+ arr.entries() -

Valeur de retour

+### Valeur de retour -

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

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

Exemples

+## Exemples -

Parcourir un tableau avec ses index et éléments

+### Parcourir un tableau avec ses index et éléments -
const arr = ["a", "b", "c"];
+```js
+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

+### Boucle `for...of` -

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

+On peut avoir le même résultat en utilisant une boucle [for...of](/fr/docs/Web/JavaScript/Reference/Instructions/for...of) : -
var arr = ['a', 'b', 'c'];
+```js
+var arr = ['a', 'b', 'c'];
 var eArr = arr.entries();
 
 for (let e of eArr) {
@@ -51,42 +53,25 @@ for (let e of eArr) {
 // [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

- - +``` + +## Spécifications + +| Spécification | État | Commentaires | +| ------------------------------------------------------------------------------------------------------------ | ---------------------------- | -------------------- | +| {{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 + +- {{jsxref("Array.prototype.keys()")}} +- {{jsxref("Array.prototype.values()")}} +- {{jsxref("Array.prototype.forEach()")}} +- {{jsxref("Array.prototype.every()")}} +- {{jsxref("Array.prototype.some()")}} +- [`for...of`](/fr/docs/Web/JavaScript/Reference/Instructions/for...of) +- [Les protocoles d'itération](/fr/docs/Web/JavaScript/Reference/Les_protocoles_iteration) -- cgit v1.2.3-54-g00ecf