From 218934fa2ed1c702a6d3923d2aa2cc6b43c48684 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:43:23 -0500 Subject: initial commit --- .../reference/global_objects/set/has/index.html | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 files/zh-tw/web/javascript/reference/global_objects/set/has/index.html (limited to 'files/zh-tw/web/javascript/reference/global_objects/set/has') diff --git a/files/zh-tw/web/javascript/reference/global_objects/set/has/index.html b/files/zh-tw/web/javascript/reference/global_objects/set/has/index.html new file mode 100644 index 0000000000..c77d2ea99b --- /dev/null +++ b/files/zh-tw/web/javascript/reference/global_objects/set/has/index.html @@ -0,0 +1,92 @@ +--- +title: Set.prototype.has() +slug: Web/JavaScript/Reference/Global_Objects/Set/has +tags: + - ECMAScript 2015 + - JavaScript + - 原型 + - 方法 + - 集合 +translation_of: Web/JavaScript/Reference/Global_Objects/Set/has +--- +
{{JSRef}}
+ +

has() 方法對一個指定值元素在 Set 物件中的存在與否回傳一個布林值。

+ +
{{EmbedInteractiveExample("pages/js/set-prototype-has.html")}}
+ + + +

語法

+ +
mySet.has(value);
+ +

參數

+ +
+
value
+
要測試是否存在在 Set 中的值。
+
+ +

回傳值

+ +

回傳 true 如果給定值存在在 Set 物件中;反之回傳 false

+ +
+

Note: 技術上來說,has() 使用了 sameValueZero 算法來判斷給定元素的存在與否。

+
+ +

範例

+ +

使用 has 方法

+ +
var mySet = new Set();
+mySet.add('foo');
+
+mySet.has('foo');  // returns true
+mySet.has('bar');  // returns false
+
+var set1 = new Set();
+var obj1 = {'key1': 1};
+set1.add(obj1);
+
+set1.has(obj1);        // returns true
+set1.has({'key1': 1}); // returns false because they are different object references
+set1.add({'key1': 1}); // now set1 contains 2 entries
+
+ +

規範

+ + + + + + + + + + + + + + + + + + + +
規範狀態
{{SpecName('ES2015', '#sec-set.prototype.has', 'Set.prototype.has')}}{{Spec2('ES2015')}}Initial definition.
{{SpecName('ESDraft', '#sec-set.prototype.has', 'Set.prototype.has')}}{{Spec2('ESDraft')}} 
+ +

瀏覽器相容性

+ + + +

{{Compat("javascript.builtins.Set.has")}}

+ +

另見

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