I am dealing with 2 different arrays of objects
var array1 = [
{id: 1, name:'fruit', rating:5},
{id: 4, name:'vegetable', rating: 3},
{id: 8, name:'meat', rating:1}
];
var array2 = [
{alimentId: 1, quantity: 2},
{alimentId: 4, quantity: 2},
{alimentId: 8, quantity: 4}
]
and my goal is to create a new array that contains only specific elements from array1 based on certain conditions.
var array = [
{id: 1, name:'fruit'},
{id: 4, name:'vegetable'},
]
I need help in filtering out the elements with quantity 2 that match the alimentId with the id. Arrays and object manipulations confuse me at times, any assistance would be greatly appreciated.