统计html中出现最多的标签

查找当前页面中出现最多的 html 标签

1
2
3
4
5
6
7
8
9
10
const maxBy = (list, keyBy) => list.reduce((x, y) => keyBy(x) > keyBy(y) ? x : y)

function getFrequentTag () {
const tags = [...document.querySelectorAll('*')].map(x => x.tagName).reduce((o, tag) => {
o[tag] = o[tag] ? o[tag] + 1 : 1;
return o
}, {})
return maxBy(Object.entries(tags), tag => tag[1])
}

转载文章:
(原文连接)[https://juejin.cn/post/6922229465468633095]


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!