reponの勉強メモ

主に勉強したことのメモです。

2つの配列から重複した要素を抽出する

JavaScriptの配列操作に役立つ13のヒントとトリック - Qiita様より

const numOne = [0, 2, 4, 6, 8, 8];
const numTwo = [1, 2, 3, 4, 5, 6];

const firstValueSet = new Set( numOne ) ;
const duplicatedValues = numTwo.filter( item => firstValueSet.has(item) );

console.log(duplicatedValues); // [2, 4, 6]