let str="Rome was not built in a day"; let map = []; for (let i = 0; i < str.length; i++) { let char = str[i]; if (map[char]) { map[char]++; } else { map[char] = 1; } } console.log("一共出现了"+Object.keys(map).length+"个字母") for (let key in map) { console.log(key + "出现了" + map[key] + "次"); }