WeakMap.prototype.has()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
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
.
Exemple interactif
const weakmap1 = new WeakMap();
const object1 = {};
const object2 = {};
weakmap1.set(object1, "foo");
console.log(weakmap1.has(object1));
// Expected output: true
console.log(weakmap1.has(object2));
// Expected output: false
Syntaxe
wm.has(clé);
Paramètre
clé
-
Ce paramètre est obligatoire. Il correspond à la clé de l'élément dont on souhaite savoir s'il est présent dans l'objet
WeakMap
.
Valeur de retour
La méthode renvoie true
s'il existe un élément du WeakMap
avec la clé donné, false
sinon.
Exemples
var wm = new WeakMap();
wm.set(window, "toto");
wm.has(window); // renvoie true
wm.has("machin"); // renvoie false
Spécifications
Specification |
---|
ECMAScript® 2025 Language Specification # sec-weakmap.prototype.has |
Compatibilité des navigateurs
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
has |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.