how can I search duplicate data using index key object here is my object :
const obj = {
product1: { name: 'paper', price: 4 },
product2: { name: 'ball', price: 2 },
product3: { name: 'ice-cream', price: 9 }
product1: { name: 'paper', price: 2 }
}
and I have an arrays
const arr = ["product1", "product2" ]
I want to get only product1 and product2 data then sum price together my output shold look like this 4+2+2 = 8
Here is what I try to do
const newArr = _.map(arr, (name:string) => {
return obj[name]
})
then I sum
const sum = newArr.reduce((data, obj)=> data + obj.price, 0);
the problem is in _.map when I map data if I return like this it will get only 1 product1 I want to get all of product name in arr