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 loop through the *lst* and update the *total* by counting the fruits in the *newlst* using `filter()`

```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"];

lst.forEach(function(fruit){
  //get the count in newlst
  let count = newlst.filter(f => f == fruit.name).length;
  //update the total by adding
  fruit.total = fruit.total + count;
});

console.log(lst);
```
We can `map` through the `list` and filter out items in the `newList` based on the item being mapped in the `list`. The length of the filter output will give us the number of occurrences of the item in the `newList` and based on that we can derive the `total` logic.

```js
const list = [{name: 'Apple', total: 4}, {name: 'Mango', total: 9}, 
{name: 'Orange', total: 6}, {name: 'Passion', total: 2}];

const newList = ['Apple', 'Orange', 'Banana', 'Mango', 'Apple', 'Pineapple', 'Passion'];

const result = list.map((x) => {
  const numberOfOccurences = newList.filter((y) => y === x.name).length
  return {
    ...x,
    total: x.total + numberOfOccurences
  };
});

console.log(result);
```