Basically, here is what I am trying to do.
- Go through each entry of the 'food' array and check whether the 'category' value is included in the 'target' array.
- Insert another key/value pair (target:true or target:false) accordingly.
i.e.,
const food = [
{category: 'fruit', price: 5},
{category: 'meat', price: 10},
{category: 'drink', price: 3}
];
const target = ['fruit', 'meat'];
const result = [
{category: 'fruit', price: 5, target: true},
{category: 'meat', price: 10, target: true},
{category: 'drink', price: 3, target: false}
];
What will be the code to do this? Thanks a lot in advance!