title: React - Check if a value already exists in an array?
body: <p>I'm working on a simple React shopping list where you can add/remove items from a list (<a href="https://codepen.io/ash-thomas/pen/pBzqJN" rel="nofollow noreferrer">pen here</a>). It's working great so far except if you add a duplicate entry to the list and try and delete it, it gets confused (it's using the value as the key, so presumably that's why). To get around this I'd like to check if the value already exists in the list array when you add an item, and prevent it from being added. I've tried adding another check in the handleAddNew function by changing this: <code>if (this.state.newItem.length &gt; 0){</code> to this: <code>if (this.state.newItem.length &gt; 0 &amp;&amp; this.state.items.includes(this.state.newItem) == false){</code> (line 18), but that doesn't seem to be working. Any ideas on how I should go about doing this?</p>