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

201
Views
What's the cleanest way to turn an object into a list without using a double for loop?

I have an object called 'times', that holds another object called '20102', that holds a list of 3 objects. It looks like this:

times: {
    20102: [
        { name:'jane', age:12 },
        { name:'josh', age:19 },
        { name:'jill', age:14 },
    ]
}

However, what I want it to look like is this:

times:[
    { name:'jane', age:12 },
    { name:'josh', age:19 },
    { name:'jill', age:14},
]

I was thinking of doing a double for loop but that's not efficient. What's a better way?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

using Object.values() and flat()

var x = {
  times: {
    20102: [{
        'key': '1'
      },
      {
        'key': '2'
      },
      {
        'key': '3'
      },
    ]
  }
};
x.times = Object.values(x.times).flat();

console.log(x);

If you know there will only be one key

var x = {
  times: {
    20102: [{
        'key': '1'
      },
      {
        'key': '2'
      },
      {
        'key': '3'
      },
    ]
  }
};
x.times = Object.values(x.times)[0];

console.log(x);

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!