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

263
Vistas
How to combine the received data in a state?

When I execute an API request, I get a lot of objects that are not connected by a common array. I'm trying to combine them into one state, but only one value is stored. How can I store all the received objects in the general array of my state? Everything would be fine, but I need the array to be stored in the state, in which all objects from the API will lie, in order to transfer this array to Redax

 const [planets, setPlanets] = useState([]);

useEffect(() => {
 (async () => {
  const users = await axios(world);
  const worldData = users.data;
  setPlanets(worldData);
 })();
 }, [nextTeam, world]);

and i take get data

enter image description here

I am trying to transfer all these objects to state planets, but objects are transferred there individually. Not creating an array.

This is a screenshot of console.log(planets)

enter image description here

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

0

You can use Object.keys

let planets = {
  tatooine:{
    population: "1,3M", type: "desert"
  },
  coruscant:{
    population: "130B", type: "city"
  },
}
let array = []
Object.keys(planets).forEach(planet => array.push({
    name: planet,
    ...planets[planet]
}))
console.log(array)

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