Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Pustur
Last active April 3, 2019 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pustur/cdeffc222450cb4c814b6831cfc2d8a5 to your computer and use it in GitHub Desktop.
Save Pustur/cdeffc222450cb4c814b6831cfc2d8a5 to your computer and use it in GitHub Desktop.
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