title: angularjs compare two arrays
body: <p>How I can compare two arrays in AngularJS, and return the matching values?</p>
  
  <p>Here is the first array: </p>
  
  <pre><code>[{
      "id":2,
      "student_name":"LiSa",
      "alien":"A",
      "world":"Sun",
      "justification":"i like sent this one",
      "submit_time":null
  },{
      "id":1,
      "student_name":"Liz",
      "alien":"B",
      "world":"Earth",
      "justification":null,
      "submit_time":"2014-09-25T08:37:34.526-05:00"
  }]
  </code></pre>
  
  <p>Here is the second one:</p>
  
  <pre><code>[{
      "id":1,
      "alien":"A",
      "world":"Sun",
      "color":"red"
  },{
      "id":2,
      "alien":"A",
      "world":"Mercury",
      "color":"red"
  },{
      "id":3,
      "alien":"B",
      "world":"Earth",
      "color":"red"
  },{
      "id":4,
      "alien":"B",
      "world":"Moon",
      "color":"red"
  }]
  </code></pre>
  
  <p>I want to check if the values for <strong>alien</strong> and <strong>world</strong> are matching in these two arrays. Then I can get the <strong>color</strong> value from the second array.</p>
  
  <p>Here is the code I put in the controller:</p>
  
  <pre><code>angular.forEach(arr1, function(value1, key1) {
      angular.forEach(arr2, function(value2, key2){
          if(value1.alien === value2.alien &amp;&amp; value1.world === value2.world){
              console.log(value2.color);
  
          }
      });
  });
  </code></pre>
  
  <p>Shall I use <code>angular.forEach</code>? How can I do that? And where do I store the color value?</p>