Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JavaScript – Return an object of all the html tag names and the number of times they appear in the document
const uniqueDomElements = () =>
Array.from(document.querySelectorAll('*')).reduce(
(obj, { tagName }) => {
obj[tagName] = obj[tagName] + 1 || 1;
obj._total += 1;
return obj;
},
{ _total: 0 }
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.