--- title: WeakMap.prototype.has() slug: Web/JavaScript/Reference/Global_Objects/WeakMap/has tags: - ECMAScript 2015 - JavaScript - Méthode - Prototype - Reference - WeakMap translation_of: Web/JavaScript/Reference/Global_Objects/WeakMap/has original_slug: Web/JavaScript/Reference/Objets_globaux/WeakMap/has ---
La méthode has() renvoie un booléen qui indique s'il existe (ou non) un élément avec une clé donnée au sein de l'objet WeakMap.
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 !
wm.has(clé);
cléWeakMap.La méthode renvoie true s'il existe un élément du WeakMap avec la clé donné, false sinon.
var wm = new WeakMap();
wm.set(window, "toto");
wm.has(window); // renvoie true
wm.has("machin"); // renvoie false
| Spécification | État | Commentaires |
|---|---|---|
| {{SpecName('ES2015', '#sec-weakmap.prototype.has', 'WeakMap.prototype.has')}} | {{Spec2('ES2015')}} | Définition initiale. |
| {{SpecName('ESDraft', '#sec-weakmap.prototype.has', 'WeakMap.prototype.has')}} | {{Spec2('ESDraft')}} |
{{Compat("javascript.builtins.WeakMap.has")}}