Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
Multi-Level Occurrence Counting in Javascript

I am trying to count the occurrences of values for multiple objects in an array in Javascript. For the following example input (original data is much larger):

input= [
   {
      Name: "James",
      Department: "Engineering",
      employeeId: 26
   },
   {
      Name: "Roger",
      Department: "Design",
      employeeId: 21
   },
   {
      Name: "John",
      Department: "Engineering",
      employeeId: 32
   },
   {
      Name: "Roger",
      Department: "Engineering",
      employeeId: 42
   },
   {
      Name: "Roger",
      Department: "Engineering",
      employeeId: 36
   }

For this I am trying to get the following output:

Output = [
{Name: 'James', Department: 'Engineering', count:1},
{Name: 'Roger', Department: 'Design', count:1},
{Name: 'John', Department: 'Engineering', count:1},
{Name: 'Roger', Department: 'Engineering', count:2},
]

I am trying to use loops and if statements given that I am new to JS. I tried implementing variations to what is provided on

https://www.geeksforgeeks.org/how-to-count-number-of-occurrences-of-repeated-names-in-an-array-of-objects-in-javascript/.

While its counting correctly, I cant seem to capture all the groupings. Any help here would be really appreciated!

Thanks!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda