- with
some
function test(arr1,arr2){
return arr1.filter(el1=>{
return arr2.some(el2=>{
return el2 === el1
})
})
}
console.log(test([1,2,3,4],[3,4,5,6]))
- with
includes
function test(arr1,arr2){
return arr1.filter(item => arr2.includes(item));
}
console.log(test([1,2,3,4],[3,4,5,6]))
Maybe there are better way to solve this task?