Method 1: Normal scale
1. Build a new temporary array to store the results
2. Take an element from the original array every time in the for loop, and use this element to loop with the temporary array.
3. If there is no element in the temporary array, it will be saved in the temporary array.
Method 2: The default Js array sort is used, which is sorted by ASCII;
To be arranged in ascending order, as follows: <Console Print Output>
1.Sort the current array first
2. Check whether the i-th element in the current is the same as the last element in the temporary array, because it has been sorted, the duplicate elements will be in adjacent positions.
3. If not the same, save the element into the result array
Method 3: <Recommended>Whether there is a property value using json object
1. Create a new array to store the results
2. Create an empty object json
3. During the for loop, each time an element is taken out to compare with the object. If this element is not repeated, it is stored in the result array. At the same time, the content of this element is taken as an attribute of the object and assigned a value of 1, and stored in the object established in step 2.
Note: As for how to compare, it is to take an element from the original array each time and then access this property into the object. If the value can be accessed, it means it is repeated.
The above article how to efficiently remove duplicates in js array is all the content I share with you. I hope it can give you a reference and I hope you can support Wulin.com more.