如何在JavaScript数组中查找重复值?
要在JavaScript中查找重复值,您可以尝试运行以下代码-
示例
<html> <body> <script> function removeDuplicate(arr) { var c; var len = arr.length; var result = []; var obj = {}; for (c = 0; c<len; c++) { obj[arr[c]] = 0; } for (c in obj) { result.push(c); } return result; } var myArr = [10, 20, 30, 40, 10, 40, 70, 80, 70, 90]; document.write(removeDuplicate(myArr)); </script> </body> </html>
输出结果
10,20,30,40,70,80,90