1.使用ES6的Set进行去重
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>数组去重</title> </head> <body> <script type="text/javascript"> function array_dedup(arr){ return Array.from(new Set(arr)); } let arr=array_dedup([1,2,3,3,4,5,5,6]); console.log(arr);//1,2,3,4,5,6 </script> </body> </html>