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

160
Visualizações
When fetching JSON and inputting the data into variable, it gives me undefined is not iterable (cannot read property Symbol(Symbol.iterator))

I'm using the Advice Slip API. As the title says, when I input the JSON data into the variable, like this:

 let advi;
fetch("https://api.adviceslip.com/advice").then(r => r.json()).then(adv => advi = adv);

It gives me the error that I mentioned. However, when I replace .then(adv => advi = adv) with .then(console.log) it gives me an object with the advice. However, since I don't want to just console.log the advice as I need to use it in my website, I need to find a way to use it in a variable.

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

0

index.js

function showData() {
let advi;
fetch("https://api.adviceslip.com/advice").then(r => r.json()).then(adv => {
    advi = adv;
    console.log(advi);
  })
}

showData();

about 4 years ago · Juan Pablo Isaza Relatório

0

If you are trying to iterate advi just below call fetch api, yes the advi variable is still undefined, because fetch is Web API which is asynchronous.

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