Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

112
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!