--- title: Set.prototype.has() slug: Web/JavaScript/Reference/Global_Objects/Set/has tags: - ECMAScript 2015 - JavaScript - Method - Prototype - Reference - set translation_of: Web/JavaScript/Reference/Global_Objects/Set/has ---
has() 메서드는 Set 객체에 주어진 요소가 존재하는지 여부를 판별해 반환합니다.
mySet.has(value);
valueSet 객체에서 존재 여부를 판별할 값.Set 객체에 값이 존재하면 true, 아니면 false.
참고: 기술적으로, has()는 sameValueZero 알고리즘을 사용해 요소의 존재 여부를 판별합니다.
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개로 늘어남
| 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")}}