새로운 세트(( 반복 가능 ))
Set()은 모든 값이 중복되지 않도록 하나씩 수집하는 Collection 객체라고 합니다.
let arr = (1,2,2,3,4,4,5);
let newCollection = new Set(arr);
let newArr = (...newCollection);
console.log(newCollection); //{1, 2, 3, 4, 5}
console.log(newArr); //(1, 2, 3, 4, 5)
if(arr.length !== newCollection.size) console.log('중복있음'); //중복있음
위의 예와 같이 arr.length와 newCollection.size를 비교하거나 Set()으로 생성한 Collection 객체를 다시 배열로 변환하여 비교하여 중복 여부를 확인할 수 있습니다.
