Created
June 16, 2022 18:37
-
-
Save juanbrusco/b9daf231b90b71a0f52bab6d0174c04a to your computer and use it in GitHub Desktop.
Count duplicates within an Array of Objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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