Question: I have this lst, which has the name and total available.

```
let lst = [
  { name: 'Apple', total: 4 },
  { name: 'Mango', total: 9 },
  { name: 'Orange', total: 6 },
  { name: 'Passion', total: 2 }
]

```

Now there is a new list json which I receive from an api, that only has names of the items, I changed to an array like this.

```
let newlst = ["Apple","Orange","Banana","Mango","Apple","Pineapple","Passion"]

```

So how do I go on about for each item in `newlst` that is found in `lst` array then sum their total +1 .... If not then skip.

So expected out is

```
let lst = [
  { name: 'Apple', total: 6 },
  { name: 'Mango', total: 10 },
  { name: 'Orange', total: 7 },
  { name: 'Passion', total: 3 }
]

```

Answer: 
you can do it by loop also. compare the array elements and json object name and than increase the total of that corresponding json object.

```
let lst = [
  { name: 'Apple', total: 4 },
  { name: 'Mango', total: 9 },
  { name: 'Orange', total: 6 },
  { name: 'Passion', total: 2 }
];
let newlst = ["Apple","Orange","Banana","Mango","Apple","Pineapple","Passion"];
for(i=0;i<lst.length;i++){
    for(j=0;j<newlst.length;j++){
         if(lst[i].name === newlst[j]){
            lst[i].total++;
          }    
    }
 }
 console.log(lst)

```
1. Create a `Map` out of `newlst` whose keys represent they **fruit name** and values represent the **fruit count**.
2. Loop over `lst` and check if the current fruit is in the `Map` then increment count otherwise leave as is.

```js
let lst = [{ name: "Apple", total: 4 }, { name: "Mango", total: 9 }, { name: "Orange", total: 6 }, { name: "Passion", total: 2 }];

let newlst = ["Apple", "Orange", "Banana", "Mango", "Apple", "Pineapple", "Passion"];

const m = newlst.reduce((r, f) => r.set(f, (r.get(f) || 0) + 1), new Map());

console.log(
  lst.map((f) => (m.has(f.name) ? { ...f, total: f.total + m.get(f.name) } : f))
)
```