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

212
Vistas
Convert an object into array javascript

I have an object with these key-value pairs. This object comes from an API which I am calling :

APIName(obj).subscribe((res:any) => {
   console.log(Object.values(res.data));
})  



data = {
   0 : 1,
   1: 3,
   2: 7,
   3: 10
....so on
}

enter image description here

simply put it is an object of numbers and my desired output is (a simple array) :

data = [1,3,7,10]

I've tried Object.value and Object.key it still converts it into an object. Any help?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

First of all if your data is not sorted by key. Then sort it. and iterate through object and push to array.

var data = {
   1: 1,
   0: 3,
   2: 7,
   3: 10
};
let sortedKeys = Object.keys(data).sort();
let arrayOfData = [];
// iterate method
sortedKeys.forEach((key) => {
  arrayOfData.push(data[key]);
});
console.log(arrayOfData);

about 4 years ago · Santiago Trujillo 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