Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

240
Views
¿Cómo imprimir toda la matriz (pokeapi)?

Tengo este código en el que intento imprimir el contenido de la matriz 'stats' del pokeapi, pero cuando se llama a la función en el navegador, solo obtengo el último elemento de esa matriz.

¿Cómo obtenerlo todo en el lado HTML? ¡Gracias!

principal.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: donde intento imprimir el contenido de la matriz

 <input id="poke-screen-id" type="text" placeholder="stats">
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

por favor encuentre debajo del código. O verifique el código sandbox aquí datos ficticios. https://codesandbox.io/s/javascript-bifurcado-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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!