Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
.map is not a function (api result)

I'm trying to map an api result to display the data but when I launch my code the console shows TypeError: pokemons.map is not a function but I do the same in another script and it's working there. I don't understand why this time .map doesn't work.

const result = document.getElementById('result');
const form = document.querySelector('form');
let pokemons = [];

async function fetchPokemon() {
  fetch(`https://pokeapi.co/api/v2/pokemon/ditto`)
    .then((res) => res.json())
    .then((data) => (pokemons = data));

  console.log(pokemons)
};

fetchPokemon();

function pokemonDisplay() {

  result.innerHTML = pokemons.map(
    (pokemon) =>
    `
    <h2>${pokemon.forms[0].name}</h2>
    `
  )
}

form.addEventListener('submit', (e) => {
  e.preventDefault();
  fetchPokemon().then(() => pokemonDisplay());
})
console.log(result);
<div class="app">
  <form action="">
    <label for="search">Entrez le nom d'un pokemon (en anglais)</label>
    <input type="text" id="search" placeholder="ex : ditto">
  </form>

  <ul id="result"></ul>
</div>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

https://pokeapi.co/api/v2/pokemon/ditto return object not array (Ditto pokemon). map is the function of Array, that is why you catch this error.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda