Map.prototype
Map.prototype
属性表示Map
构造函数的原型对象。
| Map.prototype
属性的属性特性 |
|:----|
| Writable | no |
| Enumerable | no |
| Configurable | no |
描述
Map
实例继承自Map.prototype
。你可以使用这个构造函数的原型对象来给所有的Map实例添加属性或者方法。
属性
Map.prototype.constructor
Returns the function that created an instance's prototype. This is the Map
function by default.Map.prototype.size
Returns the number of key/value pairs in the Map
object.
方法
Map.prototype.clear()
移除Map对象的所有键/值对 。
Map.prototype.delete(key)
移除任何与键相关联的值,并且返回该值,该值在之前会被Map.prototype.has(key)返回为true。之后再调用Map.prototype.has(key)会返回false。
Map.prototype.entries()
返回一个新的Iterator
对象,它按插入顺序包含了Map对象中每个元素的[key, value]数组
。
Map.prototype.forEach(callbackFn[, thisArg])
按插入顺序,为Map
对象里的每一键值对调用一次callbackFn函数。如果为forEach提供了thisArg,它将在每次回调中作为this值。
Map.prototype.get(key)
返回键对应的值,如果不存在,则返回undefined。
Map.prototype.has(key)
返回一个布尔值,表示Map实例是否包含键对应的值。
Map.prototype.keys()
返回一个新的Iterator
对象, 它按插入顺序包含了Map对象中每个元素的键。
Map.prototype.set(key, value)
设置Map对象中键的值。返回该Map对象。
Map.prototype.values()
返回一个新的Iterator
对象,它按插入顺序包含了Map对象中每个元素的值。
Map.prototype[@@iterator]()
返回一个新的Iterator
对象,它按插入顺序包含了Map对象中每个元素的[key, value]数组
。
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Map.prototype' in that specification. | Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262)The definition of 'Map.prototype' in that specification. | Draft | |
浏览器兼容性
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 38 | (Yes) | 13 (13) | 11 | 25 | 7.1 |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | No support | 38 | (Yes) | 13.0 (13) | No support | No support | 8 |
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com