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

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

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