Skip to content
Advertisement

Finding data from one array by looping another array (MongoDB, Javascript)

I have 2 arrays.

JavaScript

I want to get an array of objects with same id. Like when I go get all the object of 1 then I will loop through array2 and get the object then put them in a 3rd array.

I’m stuck at this point.

Update:

Thanks to flyingfox for solving my issue. But I see that if i have duplicate value in array1 the array2 doenst include it multiple time.

JavaScript

Advertisement

Answer

If you just want to put all elements with same id into a new array,then below is a reference for you

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement