Answer the question
In order to leave comments, you need to log in
How to recursively extract the data of an array of objects?
Hello! I have an evolves_to array from the Pokemon Species API:
I need to pull a species object from each evolves_to. How can one recursively pull from such a nested object?
I tried to write this, but something blunted on how to return data
export const getEvoChain = (chainArray: any): any => {
console.log(chainArray)
chainArray && chainArray.map(
(element: any) => {
console.log(element.species)
if(element.hasOwnProperty('evolves_to')){
getEvoChain(element.evolves_to)
}
}
)
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question