title: Stop duplication from For loops JS
body: <p>For security reasons I am unable to post the code I am using however, I have made a mockup of what it looks like.</p>
  <pre><code>House
     Member[0]
        Name : &quot;blah&quot;
        Age : 20
        Height :160
        Cars[0]
            CarAge: 15
            VIN: 1234234
            Make: BMW
            Colors[0]
              CarColour : &quot;red&quot;
            Colors[2]
              CarColour: &quot;red&quot;
        Cars[1]
            CarAge: 2
            VIN: 1234234
            Make: BMW
            Colors[0]
              CarColour : &quot;purple&quot;
            Colors[2]
              CarColour: &quot;purple&quot;
     Member[1]
        Age : &quot;blahblah&quot;
        Name : 20
        Height :143
        Cars[0]
            CarAge: 15
            VIN: 1234234
            Make: BMW
            Colors[0]
              CarColour : &quot;red&quot;
            Colors[2]
              CarColour: &quot;red&quot;
        Cars[1]
            CarAge: 13
            VIN: 123656664
            Make: Ford
            Colors[0]
              CarColour : &quot;blue&quot;
            Colors[2]
              CarColour: &quot;blue&quot;
        Cars[2]
            CarAge: 2
            VIN: 1865474
            Make: Mercedez
            Colors[0]
              CarColour : &quot;green&quot;
            Colors[2]
              CarColour: &quot;green&quot;
  </code></pre>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>var sameBrand = []; 
  var sameColor = []; 
  var sameBrand1 = [];    
  var sameColor1 = [];    
  var sameBrand2 = [];    
  var sameColor2 = [];    
  for(i=0; i&lt;House.Members[0].Cars.length; i++){
  for(x=0; x&lt;House.Members[1].Cars.length; x++){
      for(l=0 House.Members[0].Cars[i].Colors.length; l++ ){
          for(j=0 House.Members[1].Cars[x].Colors.length; j++){
              
              if(House.Member[0].Age == 20 &amp;&amp; House.Member[1].Age == 20
              &amp;&amp; House.Member[0].Cars[i].Make == "BMW" &amp;&amp; 
  House.Member[1].Cars[x].Make == "BMW"
              &amp;&amp; House.Members[0].Cars[i].Colors[l].CarColour == "red" 
  &amp;&amp; House.Members[1].Cars[x].Colors[j].CarColour){
                  sameBrand.push(House.Member[0].Cars[i].Make);
                   
  sameColor.push(House.Members[0].Cars[i].Colors[l].CarColour);
              
              }else{
                  if(House.Member[0].Age == 20 &amp;&amp; 
  House.Member[0].Cars[i].Make == "BMW"){
                      sameBrand1.push(House.Member[0].Cars[i].Make);
                       
  sameColor1.push(House.Members[0].Cars[i].Colors[l].CarColour);
                  }
                  
                  if(House.Member[1].Age == 20 &amp;&amp; 
  House.Member[1].Cars[x].Make == "BMW"){
                      sameBrand2.push(House.Member[1].Cars[x].Make);
                       
  sameColor2.push(House.Members[1].Cars[x].Colors[j].CarColour);                  
                  }
              
              }
          
          
          }
      
      }
  }
  
  
  } </code></pre>
  </div>
  </div>
  </p>
  <p>When running this code I end up with multiples and duplications as it is looping through and finding variations of all possibilities however what I need it to do:</p>
  <p>**Check that if both objects contain the same values it adds it to an array.</p>
  <p>These values should not be checked again as they have been added to the array.</p>
  <p>For all others it will add it to two separate other arrays.**
  .</p>
  <p>Im unable to use any library or functions so would have to be done in <strong>plain vanilla JS</strong></p>