delete() 方法移除 Map 对象中指定的元素。
语法
myMap.delete(key);
参数
- key
- 必须。键(key)就是要从 Map 对象中移除的元素。
返回值
如果 Map 对象中存在该元素,则返回 true 并移除它;否则如果该元素不存在则返回 false。
示例
使用 delete 方法
var myMap = new Map();
myMap.set("bar", "foo");
myMap.delete("bar"); // 返回 true。成功地移除元素
myMap.has("bar"); // 返回 false。"bar" 元素将不再存在于 Map 实例中
规范
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) Map.prototype.delete |
Standard | Initial definition. |
| ECMAScript 2017 Draft (ECMA-262) Map.prototype.delete |
Draft |
浏览器兼容性
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 38 | 13.0 (13.0) | 11 | 25 | 7.1 |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | 未实现 | 38 | 13.0 (13.0) | 未实现 | 未实现 | 8 |