title: Check for duplicates before adding to javascript array
body: <p>I have a React function, where I want to add an object to a javascript array. So far I have this</p>
  
  <pre><code> selectAnimalHandler = (animal) =&gt;{
      console.log(animal.id)
      if(this.state.animals.find(ani =&gt; ani !== animal )){
      this.setState(prevState =&gt;(
          {selectedAnimals: [...prevState.selectedAnimals, animal]}))
      }
  }
  </code></pre>
  
  <p>the logic is to check rather an element already exist in an array, and if it does not exist add it to the array. 
  I try to make a condition, rather the element exists in the array or not. 
  if it does not exist, nothing happens</p>