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

298
Views
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
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!