How to find the common elements from two arrays in Javascript

1 Answer

0 votes
const arr1 = [22, 26, 1, 8, 18, 99, 81];
const arr2 = [1, 8, 99, 5, 12, 19, 120];

let common = arr1.filter(function(obj) { return arr2.indexOf(obj) !== -1; });

console.log(common);

   
   
   
/*
run:
   
[ 1, 8, 99 ]
 
*/

 



answered Jul 26, 2020 by avibootz
...