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

188
Visualizações
How do I fetch Weather's API 'forecastday' using axios?

I use WeatherAPI's service, which returns the weather forecast given the city name The URL looks like this https://api.weatherapi.com/v1/forecast.json?key=[API_KEY]&q=tokyo&aqi=no

After trying to paste that URL into my browser and pasting the result into a JSON beautifier, here's the result

Result

Here's the weird part. I tried using axios to fetch the information from my app and printing it out, this is what it gave me

Result

It was unable to fetch forecastday and instead gave me a [Object], which didn't make any sense to me since it worked just fine on my browser

Here's my code (sorry for the spaghetti formatting) https://pastebin.com/9eJQy5Bf

I tried reinstalling the library, using proxies but the result remained the same.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

forecast.forecastday is an object array, to access a property from a particular object, you have to specify the index of the object in the array.

For example if you want the date property of the first object.

const data = {
  forecast: {
    forecastday: [{
      date: "2022-04-03"
    }]
  }
}

const date = data.forecast.forecastday[0].date; // index [0] = first element

console.log(date);

If you would have multiple days, you could loop over them or use a function like map() to get the specific items.

const data = {
  forecast: {
    forecastday: [{
        date: "2022-04-03",
        date_epoch: 123456789
      },
      {
        date: "2022-04-04",
        date_epoch: 123456789
      }
    ]
  }
}

const dates = data.forecast.forecastday.map(({ date }) => {
  return { date }
});

console.log(dates);

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