2024年07月25日 建站教程
var arr = '1,2,3,4,6,3,1,1,5,6,3,3,6,8,9,53,2' arr = arr.split(',').sort(); var newArr = []; // for (var i = 0; i < arr.length;) { var count = 0; for (var j = i; j < arr.length; j++) { if (arr[i] == arr[j]) { count++; } } newArr.push({ 'number': arr[i], 'count':count }); i += count } //遍历出重复数据 var repeat = [] for(var i = 0; i < newArr.length; i++){ if(newArr[i].count > 1){ repeat.push(newArr[i]) } } console.log('repeat',repeat)
本文链接:http://so.lmcjl.com/news/9145/