WeakSet.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 September 2015.

La méthode has() renvoie un booléen indiquant si un objet donné est contenu dans l'ensemble WeakSet.

Exemple interactif

const weakset1 = new WeakSet();
const object1 = {};
const object2 = {};

weakset1.add(object1);

console.log(weakset1.has(object1));
// Expected output: true

console.log(weakset1.has(object2));
// Expected output: false

Syntaxe

js
ws.has(valeur);

Paramètres

valeur

Ce paramètre est obligatoire. Il représente l'objet dont on souhaite savoir s'il est, ou non, présent dans l'objet WeakSet.

Valeur renvoyée

Booléen

La méthode renvoie true si l'objet WeakSet contient bien un élément avec la valeur donnée, false sinon.

Exemples

js
var ws = new WeakSet();
var obj = {};
ws.add(window);

mySet.has(window); // renvoie true
mySet.has(obj); // renvoie false

Spécifications

Specification
ECMAScript® 2025 Language Specification
# sec-weakset.prototype.has

Compatibilité des navigateurs

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
has

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Voir aussi