title: JavaScript -- find matching object in array of objects
body: <p>I am trying to search for an object in an array of objects. </p>
  
  <p>Note, vals and recs objects will be DYNAMIC.</p>
  
  <pre><code>var vals = {ID: "4", LOC: "LA", SEQ: "1"};
  
  var recs = [
    {ID:"4", LOC:"LA", SEQ:"1"},
    {ID:"4", LOC:"NY", SEQ:"1"},
    {ID:"4", LOC:"CHI",SEQ:"1"}
  
  ];
  </code></pre>
  
  <p>Now I need to check if all key:value pairs in vals already exist in recs . In this case, recs[0] is an exact match of vals. </p>
  
  <p>Heres my attempt:</p>
  
  <pre><code>var vals =  {ID: "4", LOC: "LA", SEQ: "1"};
  
  
  var recs = [
    {ID:"4", LOC:"LA", SEQ:"1"},
    {ID:"3", LOC:"NY", SEQ:"2"},
    {ID:"2", LOC:"CHI",SEQ:"3"}
  
  ];
  
  
  for(var i = 0; i&lt;recs.length; i++){  
      if(recs[i]["ID"] == vals["ID"] &amp;&amp; recs[i]["LOC"] == vals["LOC"] &amp;&amp; recs[i]["SEQ"] == vals["SEQ"]){
        console.log(true);
      }
      else{
        console.log(false);
      }  
  }
  </code></pre>
  
  <p>The above works only because I have hardcoded the keys from the vals object. In reality, the VALS object (and recs) will be DYNAMIC with X number of key:value pairs.</p>
  
  <p>So how can I modify my for loop for a dynamic vals object?</p>
  
  <p>thanks!</p>