I have an array
sourceArray = [{'type':'A'}, {'type':'B'}, {'type':'C'}, {'type':'D'}];
arrayB = ['B', 'C'];
I am looking to filter out elements in sourceArray
that are also present in arrayB
.
Rather than iterating through arrayB
, I am seeking a more efficient solution.
filteredArray = [];
for(x in arrayB)
{
filteredArray.concat( sourceArray.filter(function(e1){ return e1.type == arrayB[x])} );
}
Is there a more elegant approach to achieve this?