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

114
Vistas
How to loop over an object inside of an object

The server gives the following response:

SomeObject:{
    Object1:{
        id: 123456789,
        name: "Foo"
    },
    Object2:{
        id: 123456789,
        name: "Bar"
    }
}

Is it possible to loop over SomeObject and display both the id and name of Object1/Object2? Searching for this mostly lead to using Object.keys(SomeObject).map however those are use to get the string of Object1/Object2.

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

0

const SomeObject = { Object1: { id: 123456789, name: "Foo" }, Object2:{ id: 123456789, name: "Bar" } };

const res = 
  Object.values(SomeObject)
  .forEach(({ id, name }) => console.log(id, name));

about 4 years ago · Juan Pablo Isaza Denunciar

0

One way is with Object.values then forEach.

SomeObject = {
    Object1:{
        id: 123456789,
        name: "Foo"
    },
    Object2:{
        id: 123456789,
        name: "Bar"
    }
}

Object.values(SomeObject).forEach(function (value) {
     console.log(value.id);
     //value.name
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

The key to solving this is the Object.values() method, the result of which can be iterated using a for..of or .forEach() loop:

const SomeObject = { Object1: { id: 123456789, name: "Foo" }, Object2:{ id: 123456789, name: "Bar" } };

for( let {id,name} of Object.values( SomeObject ) ) {
    console.log( id, name );
}

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