title: Easy way to check if array of objects exists in array of objects before setting state React JS
body: <p>Consider the following:</p>
  
  <pre><code>  this.setState({
      validations: [...this.state.validations, ...validations]
    }, () =&gt; {
      // ... Do something
    });
  </code></pre>
  
  <p>Where I am doing: <code>[...this.state.validations, ...validations]</code> validations is an an array of objects.</p>
  
  <p>So for example:</p>
  
  <pre><code>// validation
  [{message: 'hello', isError: true, fieldId: 87}, ....] 
  </code></pre>
  
  <p>Essentially every time we have a validation error we set an array of objects to an array as you see above.</p>
  
  <p>The issue is that sometimes duplicate objects get added. By duplicate I mean on the message section, so <code>this.state.validations</code> could look like:</p>
  
  <pre><code>[
    {message: 'hello', isError: true, fieldId: 87}, 
    {message: 'hello', isError: true, fieldId: 87}, 
    {message: 'hello', isError: true, fieldId: 87}, 
    ...
  ]
  </code></pre>
  
  <p>What I would like to do is filter <code>this.state.validations</code> based on the message and fieldId in <code>validations</code> and say:</p>
  
  <pre><code> // If this message doesn't exist for this field id, set it.
  </code></pre>
  
  <p><strong>Is there a simple non messy way of doing this where I could use filter or something, to loop over the state validations and the validations comparing both fieldId and message and if it doesn't exist: add it?</strong></p>