Repository navigation
Expand file tree
/
Copy pathindex.md
More file actions
70 lines (46 loc) · 1.49 KB
/
Copy pathindex.md
File metadata and controls
70 lines (46 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
title: "Map : méthode values()"
short-title: values()
slug: Web/JavaScript/Reference/Global_Objects/Map/values
l10n:
sourceCommit: cd22b9f18cf2450c0cc488379b8b780f0f343397
---
La méthode **`values()`** des instances de {{JSxRef("Map")}} retourne un nouvel objet _[itérateur de tableau associatif](/fr/docs/Web/JavaScript/Reference/Global_Objects/Iterator)_ qui contient les valeurs de chaque élément de cette map dans l'ordre d'insertion.
{{InteractiveExample("Démonstration JavaScript : Map.prototype.values()")}}
```js interactive-example
const map = new Map();
map.set("0", "toto");
map.set(1, "tata");
const iterator = map.values();
console.log(iterator.next().value);
// Résultat attendu : "toto"
console.log(iterator.next().value);
// Résultat attendu : "tata"
```
## Syntaxe
```js-nolint
values()
```
### Paramètres
Aucun.
### Valeur de retour
Un nouvel [objet d'itérateur itérable](/fr/docs/Web/JavaScript/Reference/Global_Objects/Iterator).
## Exemple
### Utiliser la méthode `values()`
```js
const maMap = new Map();
maMap.set("0", "toto");
maMap.set(1, "truc");
maMap.set({}, "licorne");
const mapIter = maMap.values();
console.log(mapIter.next().value); // "toto"
console.log(mapIter.next().value); // "truc"
console.log(mapIter.next().value); // "licorne"
```
## Spécifications
{{Specifications}}
## Compatibilité des navigateurs
{{Compat}}
## Voir aussi
- L'objet natif {{JSxRef("Map.prototype.entries()")}}
- L'objet natif {{JSxRef("Map.prototype.keys()")}}