i have a list of countries with id i want to pull the country id of a specific country name
export const country_list_with_id = [
{
id: 1,
code: "AF",
name: "Afghanistan"
},
{
id: 2,
code: "AL",
name: "Albania"
},
{
id: 3,
code: "DZ",
name: "Algeria"
},
{
id: 4,
code: "DS",
name: "American Samoa"
},
...
if have country name like
countryname = algeria
is there a function to help me easily retrieve its country id
getcountryid(countryname){
return id
}
I Found a solution
getcountryid(countryname){
country_list_with_id.map(res=>{
if(res.name === country name){
return res.id
}
});
}