--- 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/Objets_globaux/Map/clear ---
La méthode clear() supprime tous les éléments d'un objet Map.
Le code source de cet exemple interactif est disponible dans un dépôt GitHub. Si vous souhaitez contribuez à ces exemples, n'hésitez pas à cloner https://github.com/mdn/interactive-examples et à envoyer une pull request !
maMap.clear();
{{jsxref("undefined")}}.
clear()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é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')}} |
{{Compat("javascript.builtins.Map.clear")}}