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

242
Visualizações
how to print all the array (pokeapi)?

I have this code where Im trying to print the content of the 'stats' array from the pokeapi, but when the function is called in the browser I just get the last element of that array.

How to get it all in the HTML side? Thanks!

main.js:

fetch(apiURL).then(response => {
 response.json();
  }
.then(data => {

  let array 
  for(let i=0; i<data.stats.length; i++ ) {
    array = data.stats[i].stat.name;
    console.log(array);           // <- I have all the array content here
  }
  pokemonFoundStats = array;
  console.log(pokemonFoundStats); // <- I just get the last element from the array

  pokemonStats(pokemonFoundStats);
 }) };

 // function for printing in the html
const pokemonStats = (pokemonStatsInfo) => {
  const allStats = document.getElementById("poke-screen-id");
  allStats.value = `  Stats: ${pokemonStatsInfo}`;
};

HTML: Where I try to print the array content

<input id="poke-screen-id" type="text" placeholder="stats">
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

please find below the code. Or check on code sandbox here dummy data. https://codesandbox.io/s/javascript-forked-ch6bky?file=/index.js

fetch(apiURL)
  .then((response) => response.json())
  .then((data) => {
    let array = [];
    for(let i=0; i<data.stats.length; i++ ) {
      array.push(data.stats[i].stat.name;);
      // console.log(array);           
      pokemonStats(array);
    }
  });
// function for printing in the html
const pokemonStats = (pokemonStatsInfo) => {
  const allStats = document.getElementById("poke-screen-id");
  allStats.value = `Stats: ${pokemonStatsInfo}`;
};
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