I have two arrays:
const arr1 = ['abc', 'def', 'ghi', 'jkl'];
const arr2 = ['123', 'abc', 'jkl', '456', '789'];
What would be the cleanest way to return arr2 without the elements of arr1?
I guess arr2.filter(x => arr1.indexOf(x) < 0) would work, but is there a cleaner way?
arr1into a Set because then all the look ups on what is inarr1will go a lot faster. But, that's not worth it for small arrays.arr2.filter(x => arr1.indexOf(x) < 0)not clean enough for you?sort arrays beforedoing the operation. And break looping after reaching the largest item in the array.