© 2026 LinearBytes Inc.
Search posts, tags, users, and pages
Marco Alka
Software Engineer, Technical Consultant & Mentor
Just store the object, then ;)
var result2 = data.reduce(function(r, e) { if (!r[e.title]) { r[e.title] = e; r[e.title].count = 0; } r[e.title].count++; return r; }, {}); console.log(Object.values(result2));
Arun Kumar
developer
I'm getting the reuslt as an object. I want the result to be in the same format as the data with new count being added.
Arun Kumar In order to do the counting, a map is ideal, however if you want an array, you'll have to transform it back to one. You can use Object.values() (docs) on result2 to get the array you are looking for...
Object.values()
result2
I added it to the answer above.
Marco Alka Thanks Marco