title: Check array for length and push or update the object within
body: <p>I'm really struggling with my code and cannot find a way to make it work.</p>
  <p>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:</p>
  <pre><code>const originals = [];
  
  if (!originals || originals.length === 0) {
    originals.push({
      &quot;name&quot;: &quot;Michael&quot;,
      &quot;age&quot;: 21,
      &quot;gender&quot;: &quot;male&quot;
    });
  } else {
    for (i = 0; i &lt; originals.length; i++) {
      if (originals[i].name !== &quot;Michael&quot;) {
        originals.push({
          &quot;name&quot;: &quot;Michael&quot;,
          &quot;age&quot;: 21,
          &quot;gender&quot;: &quot;male&quot;
        });
      }
      if (originals[i].name == &quot;Michael&quot; &amp;&amp; originals[i].age == 21) {
        originals[i].age = 22;
      }
    }
    console.log(originals);
  }
  </code></pre>
  <p>Many thanks for your help in advance.</p>