I have two arrays. I want to compare them and make a new array out of it with matched values but I want to keep duplicate values as well.
Like:
let array1 = [1, 3, 3, 3]
let array2 = [{id:1}, {id:2},{id:3}]
array1 = array1.filter(e1 => array2.some(e2 => e2.id === e1))
array2 = array2.filter(e1 => array1.some(e2 => e2 === e1.id))
output:
array2 = [{id:1}, {id:3}]
But I want to get the duplicate as well.
Desired output
array2=[{id:1}, {id:3}, {id:3}, {id:3}] //as array1 has 3 multiple time