A RetroSearch Logo

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

Search Query:

Showing content from https://developer.cdn.mozilla.net/ko/docs/Web/JavaScript/Reference/Global_Objects/Set/has below:

Set.prototype.has() - JavaScript | MDN

Set.prototype.has()

Baseline Widely available

Set 객체의 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 객체에서 존재 여부를 판별할 값.

반환 값

Set 객체에 값이 존재하면 true, 아니면 false.

예제 has() 메서드 사용하기
const mySet = new Set();
mySet.add("foo");

console.log(mySet.has("foo")); // true
console.log(mySet.has("bar")); // false

const set1 = new Set();
const obj1 = { key1: 1 };
set1.add(obj1);

console.log(set1.has(obj1)); // true
console.log(set1.has({ key1: 1 })); // false, 형태만 같은 서로 다른 객체의 참조이기 때문
console.log(set1.add({ key1: 1 })); // set1의 요소가 2개로 늘어남
명세서 브라우저 호환성 같이 보기

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