Map.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 permettant de déterminer si l'objet Map
en question contient la clé donnée.
Exemple interactif
const map1 = new Map();
map1.set("bar", "foo");
console.log(map1.has("bar"));
// Expected output: true
console.log(map1.has("baz"));
// Expected output: false
Syntaxe
maMap.has(clé);
Paramètres
clé
-
Ce paramètre obligatoire correspond à la clé dont on veut savoir si elle appartient à l'objet
Map
.
Valeur de retour
Cette méthode renvoie un booléen : true
si un élément avec cette clé existe au sein de l'objet Map
et false
sinon.
Exemples
var maMap = new Map();
maMap.set("truc", "toto");
maMap.has("truc"); // renvoie true
maMap.has("machin"); // renvoie false
Spécifications
Specification |
---|
ECMAScript® 2025 Language Specification # sec-map.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