const array = ['a' , 1, 2, 'a' , 'a', 3];
// 1: 'Set'
[...new Set(array)];
// 2: 'Filter'
array.filter((item, index) => array.indexOf(item) === index);
// 3: 'Reduce'
array.reduce((unique, item) =>
unique.includes(item) ? unique : [...unique, item], []);
// RESULT:
// ['a', 1, 2, 3]
'Programming > Javascript (Typescript)' 카테고리의 다른 글
사용하려는 npm 패키지가 타입스크립트를 지원하지 않을때 사용 가능하도록 하기 (index.d.ts) (0) | 2025.01.15 |
---|---|
Object.keys : 객체의 키값만 배열로 반환 (0) | 2024.10.06 |
브라우저 콘솔창에 사용자 정보 노출하기 (0) | 2024.06.06 |
enum to array (0) | 2024.06.05 |