Skip to content

Instantly share code, notes, and snippets.

@juanbrusco
Created June 16, 2022 18:37
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 juanbrusco/b9daf231b90b71a0f52bab6d0174c04a to your computer and use it in GitHub Desktop.
Save juanbrusco/b9daf231b90b71a0f52bab6d0174c04a to your computer and use it in GitHub Desktop.
Count duplicates within an Array of Objects
const arr = [
{
"Company": "IBM"
},
{
"Person": "ACORD LOMA"
},
{
"Company": "IBM"
},
{
"Company": "MSFT"
},
{
"Place": "New York"
}
];
let counts = arr.reduce((acc, curr)=>{
const str = JSON.stringify(curr);
acc[str] = (acc[str] || 0) + 1;
return acc;
}, {});
console.log(counts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment