How can I efficiently merge objects that share the same index in two different arrays of objects?
Below is the first array
const countries = [
{
"name": "Sweden",
"nativeName": "Sverige"
},
{
"name": "Norway",
"nativeName": "Norge"
},
{
"name": "Iceland",
"nativeName": "Ísland"
}
]
And here is the second array
const countryCodes = [
{
"country_id": "SE",
},
{
"country_id": "NO",
},
{
"country_id": "IS",
}
]
The desired output should be:
const countriesAndCodes = [
{
"name": "Sweden",
"country_id": "SE",
"nativeName": "Sverige"
},
{
"name": "Norway",
"country_id": "NO",
"nativeName": "Norge"
},
{
"name": "Iceland",
"country_id": "IS",
"nativeName": "Ísland"
}
]