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

198
Vistas
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 Respuestas
Responde la pregunta

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 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