Comparison of Two arrays in JS, clever method for deleting duplicate values (recommended), js Array
Occasionally, we need to compare two arrays and Delete the existing values of the other array in one array. The method we often use is to compare and judge and delete cyclically. Recently we have seen 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 temparray = []; // temporary array 2 for (var I = 0; I <arr2.length; I ++) {temp [arr2 [I] = true; // clever place: Treat the value of array B as the key of temporary array 1 and assign a value to true }; for (var I = 0; I <arr1.length; I ++) {if (! Temp [arr1 [I]) {temparray. push (arr1 [I]); // clever place: At the same time, the value of array A is treated as the key of the temporary array 1 and determines whether it is true. If it is not true, it indicates there are no duplicates, then, it is merged into a new array to obtain a completely new array with no duplicates} ;}; document. write (temparray. join (",") + "");
The clever method (recommended) for deleting duplicate values for comparing the above two arrays of JS is all the content shared by Alibaba Cloud xiaobian. I hope you can give us a reference and support for the customer's house.