<body> <script> var arr = [1, 1,1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,"a","a"]; var sub = []; //遍历 arr.forEach(function(value){ //indexOf查找里面的值,如果有则返回下标,否则返回-1; var index =sub.indexOf(value); if (index == -1) { sub.push(value); } })
时间: 2024-10-29 10:46:41