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

118
Views
Extract single object from list in React

I am using a weather API to fetch data for a specific city, but i'm receiving the data in a list with 5 duplicates. I need to use the city name, minTemp, maxTemp, etc. within my app.

Essentially, I just need one of the 5 objects inside the response object, but I'm not sure how I can extract and use just one.

const apiCall = await fetch(
      `http://api.openweathermap.org/data/2.5/find?q=London&appid=${weatherAPIKey}`
    );
    const response = await apiCall.json();

  this.setState({
      city: response.list.name,
      country: response.list.sys.country,
    });

Will appreciate any help!

API response object

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

0

If you're sure that all 5 objects is the same, then just access the first one (or any one)

const response = await apiCall.json();
const firstCity = response.list[0]
const { name, country } = firstCity

this.setState({
      city: name,
      country,
    });
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!