I'm trying to get a key/property from a JSON object and change all of its values, whether its nested within another object, or by itself.
I have a locale variable
const locale = "en"
and I'm trying to change the value of the returned json object depending on locale, such as
result.navTitle = result.navTitle[locale]
or
stories.map((story)=> story.navTitle = story.navTitle[locale]);
...etc
result = [
{
"data":{
"en":"English",
"fi":"Finnish"
},
"navTitle":{
"en":"English",
"fi":"Finnish"
},
"stories": [
{
"navTitle":{"en":"English","fi":"Finnish"},
"cards":[
{
"navTitle":{"en":"English","fi":"Finnish"}
},
{
"navTitle":{"en":"English","fi":"Finnish"}
}
]
},
{
"navTitle":{"en":"English","fi":"Finnish"}
}
]
}
]
I have managed to do this with repetitive .map functions but it gets long, is there any other alternative to do this?