找出数组中重复的数字,重复次数

function getRepeatNum(array) {
            let obj = {};
            let array2 = [];
            for (var i = 0, l = array.length; i < l; i++) {
                var item = array[i];
                obj[item] = (obj[item] + 1) || 1;
            }

            for (var item in obj) {
                if (obj.hasOwnProperty(item)) {
                    // console.log(item, '2333')
                    if (obj[item] !== 1) {
                        array2.push(`${item}重复${obj[item]}次`)
                    }
                }
            }
            // return obj;
            return array2;
        }

 

你可能感兴趣的:(JS,js)