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

300
Vistas
Trying to combine two arrays of data from pokeapi via an axios.get function in node.js

I'm working on a project right now where I'm accessing pokemon data from PokeAPI with axios. I am only accessing a few points of data, and one of them is the pokemon type. If the pokemon I'm searching for has two types, it will return the types as separate arrays.

For example, if I search Pikachu, it returns with just one array, which is Electric, because pikachu only has one type. However, if I search for Gengar, it will return two arrays. One with poison, and one with ghost.

How can I combine these into a single array of types?

Here is my code :

module.exports = {
  getPokemon: async (req, res) => {
    const { pokemon } = req.body;
    try {
      const { data } = await axios.get(
        `https://pokeapi.co/api/v2/pokemon/${pokemon.toLowerCase()}`
      );
      const types = data.types.map((pokemon) => pokemon.type);
      console.log(types);
      party.push({
        name: data.name,
        sprites: data.sprites.front_default,
        types: data.types,
      });
      res.status(200).send(party);
    } catch (err) {
      console.log(err);
      res.status(500).send("something went wrong");
    }
  },
};

And the response I get in the console :

name: "gengar"
sprites: "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/94.png"
types: Array(2)
0:
slot: 1
type: {name: 'ghost', url: 'https://pokeapi.co/api/v2/type/8/'}
[[Prototype]]: Object
1:
slot: 2
type: {name: 'poison', url: 'https://pokeapi.co/api/v2/type/4/'}
about 4 years ago · Juan Pablo Isaza
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