I'm really struggling with my code and cannot find a way to make it work.

I need to check whether my array exists or its length is not 0 and then if there is an object with a specific value in it. If so then update it. If not then add it. Please see my code below:

```
const originals = [];

if (!originals || originals.length === 0) {
  originals.push({
    "name": "Michael",
    "age": 21,
    "gender": "male"
  });
} else {
  for (i = 0; i < originals.length; i++) {
    if (originals[i].name !== "Michael") {
      originals.push({
        "name": "Michael",
        "age": 21,
        "gender": "male"
      });
    }
    if (originals[i].name == "Michael" && originals[i].age == 21) {
      originals[i].age = 22;
    }
  }
  console.log(originals);
}

```

Many thanks for your help in advance.
['https://Stackoverflow.com/questions/66714870', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1647297/']
Here is my quick solution to this issue:

From my perspective its a good idea to address a new array to contain temporary data.

The easiest way to describe what I mean follows in the code snippet.

Code Snippet (For-Loop)
-----------------------

```
var originalsStack=[];

function PushToOriginalStack() {

for (i=0; i < originals.length; i++) {
    if (originals[i].name != "Samantha") {
        originalsStack.push({
            "name": "Michael",
            "age": 21,
            "gender": "male"
        });

    }
    else if (originals[i].name == "Samantha" && originals[i].age == 20) {
        originals[i].age = 21;
        originalsStack.push(originals[i]);
    }

    console.log(i);
}

originals = originalsStack;
}

PushToOriginalStack();

console.log(originals);

```

Important keep your Data handy, so you can handle the originals array.
Hope I could help a bit! Cheers!
The simple solution is below with help of amazing supporters on StackOverflow. Thank you all

```js
const originals = [{
    "name": "Michael",
    "age": 21,
    "gender": "male"
}];
if (!originals || originals.length === 0) {
    originals.push({
        "name": "Michael",
        "age": 21,
        "gender": "male"
    });
} else {
    for (i = 0; i < originals.length; i++) {
        if (originals[i].name !== "Michaels") {
            originals.push({
                "name": "Michaels",
                "age": 22,
                "gender": "male"
            });
        }
        if (originals[i].name == "Michael" && originals[i].age == 21) {
            originals[i].age = 24;
        }
    }
}
console.log(originals);
```