map.size
map.size
size
可访问属性返回 Map
对象的元素数量.
描述
size
属性的值是一个整数,表示 Map
对象有多少个键值对。size
是只读属性,它对应的 set
方法是 undefined
,即不能改变它的值。
示例
使用 size
var myMap = new Map(
myMap.set('a', 'alpha'
myMap.set('b', 'beta'
myMap.set('g', 'gamma'
myMap.size // 3
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Map.prototype.size' in that specification. | Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262)The definition of 'Map.prototype.size' in that specification. | Draft | |
浏览器兼容性
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 38 | (Yes) | 19 (19) | 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) | 19.0 (19) | No support | No support | 8 |