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

339
Visualizações
Access to object info using the pokeapi JAVASCRIPT

Hey I'm just trying to do the typical pokedex using the pokeapi API with vanilla javascript I'm just returning each pokemon information into an object and it's working, but I don't know how to access the property of the objects I'm trying to access the array but it returns me undefined I don't know how to print each Pokemon name on the console.

This how I'm fetching the info:

let pokemonarray = []
const getPokemonAxios = async () => {
  for (let i = 1; i <= 5 ; i++) {
    try {
      const res = await axios(`https://pokeapi.co/api/v2/pokemon/${i}`);
      const pokemon = res.data;
      pokemonarray.push({ ...pokemon }) 

    } catch (error) {
      console.log(error)
    }
  }
}

const poke = getPokemonAxios()

console.log(pokemonarray)

This what shows on console when I print pokemonarray I don't know how to console.log elements like name or type on this object. pokeapi result

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

0

pokemonarray is an iterable so you can loop through the array using a forEach loop and then access and log the properties that are of interest to you

pokemonarray.forEach((pokemon) => {
    console.log(pokemon.name)
    })

this will log the name of each pokemon

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