# 08. 유니크한 배열, Set !
🙄 중복없이 유일한 값을 저장하려고 할때 사용한다.
이미 존재하는지 체크할 때 유용함,
# ✨ 중복없이 유일한 값을 저장
let mySet = new Set();
mySet.add("crong");
mySet.add("hary");
mySet.add("crong");
mySet.forEach(function(v) {
console.log(v);
})
# 🔎 console
"crong"
"hary"
# ✨ 이미 존재하는지 확인할 때 유용!
let mySet = new Set();
mySet.add("crong");
mySet.add("hary");
mySet.add("crong");
if (mySet.has("crong")) { // 이미 있는지 확인!
console.log("yes, i have crong!");
} else {
console.log("no .. i don't have crong TT")
}
# 🔎 console
"yes, i have crong!"
# ✨ 삭제도 가능!
let mySet = new Set();
mySet.add("crong");
mySet.add("hary");
mySet.add("crong");
mySet.delete("crong"); // 삭제도 가능
console.log(...mySet);
# 🔎 console
"hary"
# Reference
https://www.inflearn.com/course/es6-강좌-자바스크립트/dashboard (opens new window)