Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda