Not sure how do to this, so any help is greatly appreciated
Say I have :
const array1 = [1, 1, 2, 3, 4]; const array2 = [1, 2];
Desired
You could take a Map for counting the items for removing.
const array1 = [1, 1, 2, 3, 4], array2 = [1, 2], remove = array2.reduce((m, v) => m.set(v, (m.get(v) || 0) + 1), new Map), result = array1.filter(v => !remove.get(v) || !remove.set(v, remove.get() - 1)); console.log(...result);