I am putting together a Pokédex application for a school project.
My tutor suggested I use a flatMap function to display pokémon types and abilities as there is sometimes more than one.
However, they just get listed with commas between them and no spacing. I’d like to add some spacing between the pokémon types. Can anyone help me with how to do that?
Code below:
function loadDetails(pokemon) {
let url = pokemon.detailsUrl
return fetch(url)
.then(function (response) {
return response.json()
})
.then(function (details) {
pokemon.imageUrl = details.sprites.front_default
pokemon.height = details.height
pokemon.weight = details.weight
pokemon.abilities = details.abilities.flatMap(
(element) => element.ability.name
)
pokemon.types = details.types.flatMap(
(element) => element.type.name
)
})
.catch(function (e) {
console.error(e)
})
}