title: JavaScript Array length Comparison
body: <p>In my code I check if there is similar values in two arrays and if there are   similar values they wont be displayed  in my result, however if I do the same check but switch the arrays length, which means Array2 is longer than Array1 , I  got an empty result, empty array. How can I get the same result even after switching the lenght of the arrays?</p>
  
  <p>My code :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>    var Array2 = [ "1", "2", "3", "4", "5" ]; 
      var Array1 = ["1","2","3"];
        
      var result = [];
        
      
      for(var i = 0; i &lt; Array1.length ; i++){
          
          var x = Array1[i];
          var check = false;        
        
          for( var y = 0; y &lt; Array2.length; y++){
            
            if(x == Array2[y]){
             
              check = true;
            }
          }
          if(!check){
            result.push(x);
          }
      }
      console.log(result);</code></pre>
  </div>
  </div>
  </p>