Question: I have a list of items I am working through.
I am looking for specific items in the initial list and would like to delete a found item from that list while traversing the list.
I am traversing the list using `for item : list`

Is there a way of doing that without manipulating two lists?

Answer: 
Try this.

```
addObjToarray(obj) {
  let elmIndex = -1;
  const found = this.myarray.some((el, index) => {
    elmIndex = index; 
    return el.id === obj.id;
  })
  if (!found){
    this.myarray.push(obj);
  } else{
    this.myarray[elmIndex] = obj;
  }
}

```
Basic Array Manipulation
========================

You can manipulate an array in JavaScript in various ways, either by writing your own iterative code, or by utilizing the standard methods available on the Array prototype.

[See a list of methods here (developer.mozilla.org)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)

Breaking down your task, we need to do the following:

* Determine if an element is in an array, by the object's id
* add the object if it is not there.
* update the object if it is there.

You already solved the first part of calling `arr.push(obj)` in the negative case, so looking at the positive case, what you need to do is to determine the index of the item you wish to update, and then update the item.

Determining the index of an element
-----------------------------------

Looking at the documentation linked above, we can see that there is a method provided which perfectly suits our needs `findIndex()`

So, given we need to both know the index, and check whether to go the positive or negative path our code becomes:

```js
function updateOrPushToArr(obj, arr) {
 const objIndex = arr.findIndex(inArray => inArray.id == obj.id);
 if(objIndex > -1) {
  arr[objIndex] = obj;
 } else {
  arr.push(obj);
 }
}

```