I'm attempting to modify an array of objects with lodash, and struggling a bit. I would like to take the array below and change the keys in the objects.
Here is my source array:
[
{
"id": "AD",
"name": "Andorra",
"currency": "EUR",
"timezone": "Europe/Andorra",
"links": [
{
"rel": "self",
"href": "http://localhost:8000/api/countries/AD"
},
{
"rel": "country.currency",
"href": "http://localhost:8000/api/currencies/EUR"
}
]
},
{
"id": "AE",
"name": "United Arab Emirates",
"currency": "AED",
"timezone": "Asia/Dubai",
"links": [
{
"rel": "self",
"href": "http://localhost:8000/api/countries/AE"
},
{
"rel": "country.currency",
"href": "http://localhost:8000/api/currencies/AED"
}
]
},
...
]
I would like this to result in:
[
{
"value": "AD",
"title": "Andorra",
"currency": "EUR",
"timezone": "Europe/Andorra",
"links": [
{
"rel": "self",
"href": "http://localhost:8000/api/countries/AD"
},
{
"rel": "country.currency",
"href": "http://localhost:8000/api/currencies/EUR"
}
]
},
{
"value": "AE",
"title": "United Arab Emirates",
"currency": "AED",
"timezone": "Asia/Dubai",
"links": [
{
"rel": "self",
"href": "http://localhost:8000/api/countries/AE"
},
{
"rel": "country.currency",
"href": "http://localhost:8000/api/currencies/AED"
}
]
},
...
]
Note that the first two keys are renamed. I know I can use _.mapKeys to modify the keys, however I'm not sure how to iterate the array in the best way to do this.
Any suggestions would be much appreciated.
mapand runmapKeyson each iteration?