在线文档教程

map.has

map.has

方法has() 返回一个bool值,用来表明map 中是否存在指定元素.

语法

myMap.has(key

参数

key必填. 用来检测是否存在指定元素的键值.

返回值

Boolean如果指定元素存在于Map中,则返回true。其他情况返回false

示例

使用has方法

var myMap = new Map( myMap.set('bar', "foo" myMap.has('bar' // returns true myMap.has('baz' // returns false

规范

SpecificationStatusComment
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Map.prototype.has' in that specification.StandardInitial definition.
ECMAScript Latest Draft (ECMA-262)The definition of 'Map.prototype.has' in that specification.Living Standard

浏览器兼容性

FeatureChromeEdgeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support38(Yes)13.0 (13.0)11257.1

FeatureAndroidChrome for AndroidEdgeFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic supportNo support38(Yes)13.0 (13.0)No supportNo support8