I have a function that needs to return the id of a country.
My list is an array of objects :
{
id: 2,
code: "AL",
name: "Albania"
}...
Here is my function to get the id needed from country
getCountryID(countryName) {
return country_list_with_id.forEach(res => {
if (res.name.toLowerCase() === countryName) {
console.log("the id is",res.id)// the log is 143
let id = res.id;
return id;
}
});
}
console.log(array.getCountryID("USA"))//undefined
so how could I get the id?