Contact: aviboots(AT)netvision.net.il
43,977 questions
57,435 answers
573 users
const array1 = [1, 2, 6, 3, 9, 5]; const array2 = [5, 6, 7, 10, 11]; const intersection = array1.filter(x => array2.includes(x)); console.log(intersection); /* run: [6, 5] */
const array1 = [1, 2, 6, 3, 9, 5]; const array2 = [5, 6, 7, 10, 11]; const intersection = array1.filter(x => array2.indexOf(x) !== -1); console.log(intersection); /* run: [6, 5] */
const arr1 = [5, 7, 1, 1, 6, 0, 2]; const arr2 = [2, 8, 8, 6, 9, 3, 3]; const intersection = [...new Set(arr1)].filter(item => arr2.includes(item)); console.log(intersection); /* run: [ 6, 2 ] */