Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save andresgallo/aad0494f3e28bd18ad2b22a5d49a0ad2 to your computer and use it in GitHub Desktop.

Select an option

Save andresgallo/aad0494f3e28bd18ad2b22a5d49a0ad2 to your computer and use it in GitHub Desktop.
dupIds
const ids = Array.from(document.querySelectorAll('[id]'))
.map(v => v.id)
.reduce((acc, v) => {
acc[v] = (acc[v] || 0) + 1;
return acc
}, {});
console.log(ids);
// To get a list of duplicate IDs:
const duplicateIds = Object.entries(ids)
.filter(([key, value]) => value > 1)
.map(([key, value]) => key);
console.log(duplicateIds);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment