Set.prototype.has()
Метод has()
возвращает логическое значение, показывающее, существует ли элемент с указанным значением в объекте Set
или нет.
Интерактивный пример
Syntax
mySet.has(value);
Parameters
- value
-
Required. The value to test for presence in the
Set
object.
Return value
- Boolean
-
Returns
true
if an element with the specified value exists in theSet
object; otherwisefalse
.Примечание: Technically speaking,
has()
uses thesameValueZero
algorithm to determine whether the given element is found.
Examples
Using the has
method
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
Specifications
Specification | Status | Comment |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) Определение 'Set.prototype.has' в этой спецификации. |
Стандарт | Initial definition. |
ECMAScript (ECMA-262) Определение 'Set.prototype.has' в этой спецификации. |
Живой стандарт |
Browser compatibility
BCD tables only load in the browser