数组去重
const arr = [1, 1, 2, 3, 4, 7, 5, 6, 3, 4, 1];
const newArr = Array.from(new Set(arr));
const newArr1 = [];
arr.forEach((item) => {
if (newArr1.indexOf(item) === -1) {
newArr1.push(item);
}
});
找出字符串中出现次数最多的字符
const str = 'aaabbcdd';
const strObj = {};
for (let i = 0; i < str.length; i++) {
if (str[i] in strObj) {
strObj[str[i]]++;
} else {
strObj[str[i]] = 1;
}
}
let string = '';
let count = 0;
for (const key in strObj) {
if (strObj[key] > count) {
count = strObj[key];
string = key;
}
}
console.log(string, count);