두 배열 비교 후 중복 제거

const array = [{id: 1, name: '신림'}, {id: 2, name: '양재'}] const array2 = [{id: 3, name: '봉천'}, {id: 1, name: '강남'}]
const result = a.filter(item => b.some(other => other.id === item.id));

같지 않은 것을 구할땐 other.id !== item.id 이 아닌 !b.some 를 이용해야 한다.

JP
이중표Frontend Engineer

3년차 프론트엔드 개발자. Next.js, React, TypeScript 기반 웹 애플리케이션 개발 전문. 대규모 트래픽 환경에서 SSR·ISR 렌더링 전략 설계 경험.

이력서 보기