A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Set/has below:

Set.prototype.has() - JavaScript | MDN

Set.prototype.has()

Baseline Widely available

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

嘗試一下
const set1 = new Set([1, 2, 3, 4, 5]);

console.log(set1.has(1));
// Expected output: true

console.log(set1.has(5));
// Expected output: true

console.log(set1.has(6));
// Expected output: false
語法 參數
value

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

回傳值

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

備註: 技術上來說,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
規範 瀏覽器相容性 參見

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4