I am using rick & morty API, and i want to render cards of the result where I display name, gender, location & episode name. But the object returns this.
> "results": [
{
"id": 19,
"name": "Antenna Rick",
"status": "unknown",
"species": "Human",
"type": "Human with antennae",
"gender": "Male",
"origin": {
"name": "unknown",
"url": ""
},
"location": {
"name": "unknown",
"url": ""
},
"image": "https://rickandmortyapi.com/api/character/avatar/19.jpeg",
"episode": [
"https://rickandmortyapi.com/api/episode/10"
],
"url": "https://rickandmortyapi.com/api/character/19",
"created": "2017-11-04T22:28:13.756Z"
}
]
Given the episode array, I need to show the name of the episode, not the URL. So what I do in my return is this
<h5>{'Episode: '+getEpisode(item.episode)}</h5>
const getEpisode = (item) => {
**//REQUEST TO https://rickandmortyapi.com/api/episode/10**
Requests.getEpisode(item[0]).then((res)=>{
return res.name
})
.catch((err)=>{
console.log(err)
})
}
But all I got it's undefined printed in the h5 tag, why is this ? can anybody help me
this is the content of request.getEpisode
const getEpisode = async (URL) => {
//URL = https://rickandmortyapi.com/api/character/19
const {data: res} = await axios.get(`${URL}`);
return res;
};