i need help with getting data outside the fetch function.
const getSpecies = (URL) => {
fetch(URL)
.then(response => response.json())
.then(data =>{
console.log(data.name);
})
}
I'm fetching data from API to get a one value. I don't know how return this value as a value of function. Always I get a undefined or [Promise object]
. I tried like that:
const getSpecies = async (URL) => {
const data = await fetch(URL);
const resoult = await data.json();
const species = resoult.name;
console.log(species);// value of name
return species
}
I also tried use few callbacks functions and return in all places.
I still have problems with understand asynchronous JS. That's why I need help.
age: ${getSpecies(object.species)}
` and i need to return value from this funcion. when i am doing like you said i still have promise object – mateusz lukoszek Dec 22 '20 at 15:46