Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

121
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda