aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/javascript/reference/global_objects/map/clear/index.md
blob: d53f651c14e889ef94dbc21b94432b3517472ed1 (plain)
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
---
title: Map.prototype.clear()
slug: Web/JavaScript/Reference/Global_Objects/Map/clear
tags:
  - ECMAScript 2015
  - JavaScript
  - Map
  - Méthode
  - Prototype
  - Reference
translation_of: Web/JavaScript/Reference/Global_Objects/Map/clear
original_slug: Web/JavaScript/Reference/Global_Objects/Map/clear
---
{{JSRef}}

La méthode **`clear()`** supprime tous les éléments d'un objet `Map`.

{{EmbedInteractiveExample("pages/js/map-prototype-clear.html")}}

## Syntaxe

    maMap.clear();

### Valeur de retour

{{jsxref("undefined")}}.

## Exemple

### Utiliser la méthode `clear()`

```js
var maMap = new Map();
maMap.set("truc", "bidule");
maMap.set(1, "toto");

maMap.size;        // 2
maMap.has("truc"); // true

maMap.clear();

maMap.size;        // 0
maMap.has("truc")  // false
```

## Spécifications

| Spécification                                                                                        | État                         | Commentaires         |
| ---------------------------------------------------------------------------------------------------- | ---------------------------- | -------------------- |
| {{SpecName('ES2015', '#sec-map.prototype.clear', 'Map.prototype.clear')}}     | {{Spec2('ES2015')}}     | Définition initiale. |
| {{SpecName('ESDraft', '#sec-map.prototype.clear', 'Map.prototype.clear')}} | {{Spec2('ESDraft')}} |                      |

## Compatibilité des navigateurs

{{Compat("javascript.builtins.Map.clear")}}

## Voir aussi

- {{jsxref("Map")}}