Occasionally we need to compare two arrays and delete the existing value of the other array in one array. The method we often use is to loop comparison and judge and delete. Recently, we saw another example of clever deletion of good methods:
var arr1 = ["i", "b", "c", "d", "e", "f","x"]; //Array A var arr2 = ["a", "b", "c", "d", "e", "f", "g"];//Array B var temp = []; //Temporary array 1 var temporary = [];//Temporary array 2 for (var i = 0; i < arr2.length; i++) { temp[arr2[i]] = true;//Skillful place: treat the value of array B as the key of temporary array 1 and assign the value to true}; for (var i = 0; i < arr1.length; i++) { if (!temp[arr1[i]]) { template.push(arr1[i]);//Skillful place: treat the value of array A as the key of temporary array 1 and determine whether it is true. If it is not true, it means that there is no duplication, then merge it into a new array, so that you can get a brand new array without duplication} ; }; document.write(temparray.join(",") + "");The above article is a clever way to delete duplicate values (recommended) of JS two array comparisons (recommended) which is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.