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

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

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