From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../reference/global_objects/set/has/index.html | 127 +++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 files/zh-cn/web/javascript/reference/global_objects/set/has/index.html (limited to 'files/zh-cn/web/javascript/reference/global_objects/set/has') diff --git a/files/zh-cn/web/javascript/reference/global_objects/set/has/index.html b/files/zh-cn/web/javascript/reference/global_objects/set/has/index.html new file mode 100644 index 0000000000..e9edc5d978 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/set/has/index.html @@ -0,0 +1,127 @@ +--- +title: Set.prototype.has() +slug: Web/JavaScript/Reference/Global_Objects/Set/has +tags: + - ECMAScript 2015 + - JavaScript + - set +translation_of: Web/JavaScript/Reference/Global_Objects/Set/has +--- +
{{JSRef("Global_Objects", "Set")}}
+ +

概述

+ +

has() 方法返回一个布尔值来指示对应的值value是否存在Set对象中。

+ +

语法

+ +
mySet.has(value);
+ +

参数

+ +
+
value
+
必需。用以测试该值是否存在于 Set 对象中。
+
+ +

返回值

+ +
+
Boolean
+
如果指定的值(value)存在于Set对象当中,返回true;否则返回 false
+
+ +

示例

+ +

使用 has 方法

+ +
var mySet = new Set();
+mySet.add('foo');
+
+mySet.has('foo');  // 返回 true
+mySet.has('bar');  // 返回 false
+
+var set1 = new Set();
+var obj1 = {'key1': 1};
+set1.add(obj1);
+
+set1.has(obj1);        // 返回 true
+set1.has({'key1': 1}); // 会返回 false,因为其是另一个对象的引用
+set1.add({'key1': 1}); // 现在 set1 中有2条(不同引用的)对象了
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('ES6', '#sec-set.prototype.has', 'Set.prototype.has')}}{{Spec2('ES6')}}Initial definition.
+ +

浏览器兼容性

+ +

{{ CompatibilityTable() }}

+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari
Basic support38{{CompatGeckoDesktop("13.0")}}11257.1
+
+ +
+ + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Basic support{{ CompatNo() }}38{{CompatGeckoMobile("13.0")}}{{ CompatNo() }}{{ CompatNo() }}iOS 8
+
+ +

相关连接

+ + -- cgit v1.2.3-54-g00ecf