Skip to content
Advertisement

How to enumare objects and total of them with the same key with another object in array js

I’m populing a pdf template with an array of employees, and now I need to count the number of employees working in a same department, I found a way to count the total of concurrences but I can’t enumarate the employee working in the department and the total of them. Can you help me? Thanks!!!

For example, I have this array of objects

JavaScript

Result Expected:

JavaScript

Advertisement

Answer

First you group by the department.id – then you can iterate the original array adding the correct indexes.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement