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?
My code :
var Array2 = [ "1", "2", "3", "4", "5" ]; 
var Array1 = ["1","2","3"];
      
var result = [];
      
for(var i = 0; i < Array1.length ; i++){      
  var x = Array1[i];
  var check = false;        
      
  for( var y = 0; y < Array2.length; y++){         
    if(x == Array2[y]){
      check = true;
    }
  }
  if(!check){
    result.push(x);
  }
}
console.log(result); 
     
     
     
    