This function is returning undefined and I want it to return the variable final. How can I achieve this? Please help!!
const getIndex = ()=>{
let heroName = searchfield.value
fetch(`https://akabab.github.io/superhero-api/api/all.json`)
.then(response => response.json())
.then(json => {
let result = json.find(item => item.name === `${heroName}`);
// console.log(result)
let final = (result.id);
console.log(final)
})
return final
}
This is resulting undefined. I even tried to the final variable global and then do it but still got undefined