In myI have cities with
idand
nameand
counteyidand countries with
idand
namehow to iterate this
response.valueto get a list having
cityid,name,countryid`?
you can use map function I guess, here some example with your code. I extend your list like that and result shown below
const value = [
{
id: "1",
name: "cityname",
countryId: "countryId",
countries: [{ id: 1, name: "countryname" }],
},
{
id: "2",
name: "cityname-2",
countryId: "countryId-2",
countries: [{ id: 2, name: "countryname-2" }],
},
{
id: "3",
name: "cityname-3",
countryId: "countryId-3",
countries: [{ id: 3, name: "countryname-3" }],
},
];
// you can check your list result
console.log(
value.map((m) => ({
cityId: m.id,
cityName: m.name,
countryId: m.countryId,
}))
);