I need a faster way to get all the same elements from an array existing in another one.
I have two really large arrays (A and B) with Date objects (>100k elements). Array B contains a subset from elements in Array A. I need Array A filtered for elements that are contained in Array B. So, why not just use Array B directly? I need to preserve the reference from Array A.
Currently I'm using this code:
const A = [];
const B = [];
const result = A.filter((s) => {
return B.indexOf(s) !== -1;
});
This way is quite slow. It needs over 2min to perform that action with my arrays.