title: Determine whether an array contains a value and update or create it
body: <p>So i have this Cart object in Javascript... What i want to do is check if an item is present in the given cart.</p>
  
  <ul>
  <li>If present, update its amount.</li>
  <li>If not, push it to the items array.</li>
  </ul>
  
  <p>I've done it this way</p>
  
  <pre><code>let item = {id: this.id, name: this.name, price: this.price, amount: this.amount}
  let hasItem = false;
  
  this.cart.items.forEach(element =&gt; {
      if (element.id === item.id) {
          element.amount += item.amount
          hasItem = true; 
      }
  })
  if (!hasItem) {
      this.cart.items.push(item);
  }
  </code></pre>
  
  <p>It works fine, but i was wondering if there is a faster, more effective way of doing this... What would you suggest?</p>