This article mainly introduces the method of JS to simply remove duplicate items in array, involving javascript traversal, judgment and operation related operation skills for array , Friends who need it can refer to
The example in this article describes a simple JS method to remove duplicate items in an array. Share it with everyone for your reference, the details are as follows:
<!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <script> var arr = ["aaa","bbb","aaa","ccc","ddd","ccc"]; function unique(arr) { var result = [], hash = {}; for (var i = 0, elem; (elem = arr[i]) != null; i++) { if (!hash[elem]) { result.push(elem); hash[elem] = true; } } return result; } console.info(unique(arr)); </script> </body> </html>
The renderings are as follows:
The above is the detailed content of A brief introduction to the method of removing duplicate items from an array in JS. For more information, please follow other related articles on the PHP Chinese website!