JS判断数组的值出现的次数,以及去重
var arr = ["曹阳","曹阳","曹阳","张三","张三","张三","张三","张三",]; var temp = []; var obj = {}; var newArr = []; for (var i = 0; i < arr.length; i++) { var dt = arr[i]; if (obj[dt]) { obj[dt]++; } else { temp.push(dt); obj[dt] = 1; } } console.log(temp); for (const i in obj) { newArr.push({ 'name':i, 'value':obj[i] }) } console.log(newArr);