Go straight to code

let str = 'apple';
let obj = {};
let number = 0;
let activeIndex = '';

[...str].map(key => {
    key in obj ? obj[key]++ : (obj[key] = 1);

    obj[key] > number ? (activeIndex = key) : '';
    number = obj[key];
});

console.log(activeIndex); // p
Copy the code

The content/inspiration of the article is taken from below

  • Continuous maintenance/update 500+ front end questions/notes github.com/noxussj/Int…

  • [Big data visualization chart plug-in] www.npmjs.com/package/ns-…

  • [3D city modeling using three.js (Zhuhai)] 3D.noxussJ.top /