I am looking to update the keys in an object that contains nested objects with similar structures.
Initially, my object looks like this:
objs = {
"one":{
"title":"bla",
"amount":5,
"children":[
{
"title":"bla",
"identifier":"some text"
},
{
"title":"bla2",
"identifier":"some text2"
}
]
},
"two":{
"title":"bla",
"amount":5,
"children":[
{
"title":"bla",
"identifier":"some text"
},
{
"title":"bla2",
"identifier":"some text2"
}
]
}
}
and I want to transform it into this:
objs = {
"one":{
"text":"bla",
"amount":5,
"items":[
{
"text":"bla",
"identifier":"some text"
},
{
"text":"bla2",
"identifier":"some text2"
}
]
},
"two":{
"text":"bla",
"amount":5,
"items":[
{
"text":"bla",
"identifier":"some text"
},
{
"text":"bla2",
"identifier":"some text2"
}
]
}
}
My goal is to rename every key children
to items
and every key title
to text
, regardless of how deeply nested the objects are. I have attempted using
spread & Destructuring Assignment
in forEach loops, but encountered challenges.