Map.prototype.delete()
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 delete()
permet de retirer un élément donné d'un objet Map
grâce à sa clé.
Exemple interactif
const map1 = new Map();
map1.set("bar", "foo");
console.log(map1.delete("bar"));
// Expected result: true
// True indicates successful removal
console.log(map1.has("bar"));
// Expected result: false
Syntaxe
js
maMap.delete(clé);
Paramètres
clé
-
Ce paramètre obligatoire correspond à la clé de l'élément qu'on souhaite retirer de l'objet
Map
.
Valeur de retour
Un booléen. La méthode renvoie true
si un élément de l'objet Map
a bien été retiré ou false
si l'élément n'existe pas.
Exemples
js
var maMap = new Map();
maMap.set("truc", "toto");
maMap.delete("truc"); // Renvoie true. La suppression est OK.
maMap.has("truc"); // Renvoie false. "truc" n'est plus présent.
Spécifications
Specification |
---|
ECMAScript® 2025 Language Specification # sec-map.prototype.delete |
Compatibilité des navigateurs
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
delete |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.