Analyzing the cycle is repeated

var arr1 = ["i", "b", "c", "d", "e", "f","x"]; //数组A 
   
  var arr2 = ["a", "b", "c", "d", "e", "f", "g"];//数组B 
   
  var temp = []; // temporary array 1 
   
  var temparray = []; // temporary array 2 
   
  for (var i = 0; i < arr2.length; i++) { 
   
  temp [arr2 [i]] = true; // clever place: as the key value of the array B temporary array 1 and evaluated as true 
   
  }; 
   
  for (var i = 0; i < arr1.length; i++) { 
   
  if (!temp[arr1[i]]) { 
   
  temparray.push (arr1 [i]); // clever place: while the values ​​of the array in a temporary array A 1 and determines whether the key is true if no duplicate explanation is not true, it is merged into a new array, and you can get a whole new array does not repeat 
   
  } ; 
   
  }; 
   
  document.write(temparray.join(",") + "");

 in

Guess you like

Origin www.cnblogs.com/layuechuquwan/p/11813882.html