title: Finding a Key's Value from an object within an array - Javascript
body: <p>I have tried many things to get this working correctly but I can't</p>
  
  <p>Here is my problem:</p>
  
  <p>I have an array of objects in javascript which looks something like this:</p>
  
  <pre><code>var myArrOfObjs = [];
  var myObject1 = {};
  myObject1.key = '1234';
  myObject1.label = 'Richard Clifford';
  
  myArrOfObjs.push( myObject1 );
  </code></pre>
  
  <p>and I need to do something like:</p>
  
  <pre><code>if( !containsObject( myObject1, myArrOfOjbs ) ){
      // Do stuff
  }
  </code></pre>
  
  <p>I need the <code>containsObject</code> function to check for key values within the found object (if any), so if <code>containsObject( myObject1, myArrOfOjbs )</code> finds the object, I need to check to see if the key of that is the same as the one I am currently trying to push.</p>
  
  <p>The reason I need it to check the keys is because I have tried this function which I found else where on StackOverflow, but it isn't quite working.</p>
  
  <pre><code>function containsObject(obj, list) {
      var i;
      for (i = 0; i &lt; list.length; i++) {
          if (list[i] == obj) {
              return true;
          }
      }
  
      return false;
  }
  </code></pre>
  
  <p>It still pushes the object to the array even when it already contains the object.</p>
  
  <p>Please let me know if you need anything clearing up, I realise that it isn't the easiest post to read/understand.</p>
  
  <p>Thanks!</p>