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

168
Vistas
How to loop through an object of arrays in Javascript?

For the below code,

const groupbysubject = {
                    "Mathematics":
                    [
                      {totalStudents: "23", average: "78", class: "2"},
                      {totalStudents: "25", average: "80", class: "3"}
                    ],
                    "English":
                    [
                      {totalStudents: "33", average: "98", class: "2"},
                      {totalStudents: "35", average: "99", class: "3"}
                    ],
                    "Science":
                    [
                      {totalStudents: "43", average: "65", class: "2"},
                    ]
                  }

                

var isEnglishPresent = Object.fromEntries(
                           Object.entries(groupbysubject).filter(
                             ([key, val])=> key.includes("English")
                            )
                        );

I want the following output :

"33" "98" "2" "35" "99" "3"

I have filtered the above groupbysubject object into isEnglishPresent object. How do I proceed further to iterate over isEnglishPresent and get the above output. Please help

Thank you.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You want a flat list of the values from the items inside the English key:

const groupbysubject = {
  "Mathematics":
  [
    {totalStudents: "23", average: "78", class: "2"},
    {totalStudents: "25", average: "80", class: "3"}
  ],
  "English":
  [
    {totalStudents: "33", average: "98", class: "2"},
    {totalStudents: "35", average: "99", class: "3"}
  ],
  "Science":
  [
    {totalStudents: "43", average: "65", class: "2"},
  ]
};

var englishData = groupbysubject.English.flatMap(item => Object.values(item));

console.log(englishData);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Assume you have an English array with N objects like below.

const English = [
  {totalStudents: "33", average: "98", class: "2"},
  {totalStudents: "35", average: "99", class: "3"},
  ...
]

Here's how you extract all the values and put it into an array.

English.map(item => Object.values(item)).flat()

Here's the output

["33", "98", "2", "35", "99", "3"]
about 4 years ago · Juan Pablo Isaza Denunciar
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