--- title: Set.prototype.has() slug: Web/JavaScript/Reference/Global_Objects/Set/has translation_of: Web/JavaScript/Reference/Global_Objects/Set/has ---
Метод has()
возвращает логическое значение, показывающее, существует ли элемент с указанным значением в объекте Set
или нет.
mySet.has(value);
Set
object.Returns true
if an element with the specified value exists in the Set
object; otherwise false
.
Note: Technically speaking, has()
uses the sameValueZero
algorithm to determine whether the given element is found.
has
methodvar 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
Specification | Status | Comment |
---|---|---|
{{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")}}