I am stuck on a problem trying to change the value of specific properties in a nested array of objects:
const myObj = [
{
"Description":"WA State",
"Data":[
{
"Description":"Years",
"Indicators":[
{
"Year":2018,
"Points":25994,
"Goal":"28000",
}
]
},
{
"Description":"Local Goal",
"Indicators":[
{
"Year":2018,
"Points":25994,
"Goal":"28000",
}
]
},
{
"Description":"Remote Goal",
"Indicators":[
{
"Year":2018,
"Points":55857,
"Goal":"84000",
}
]
}
]
},
{
"Description":"NY State",
"Data":[
{
"Description":"Years",
"Indicators":[
{
"Year":2018,
"Points":21953,
"Goal":"26000",
}
]
},
{
"Description":"Local Goal",
"Indicators":[
{
"Year":2018,
"Points":24195,
"Goal":"25000",
}
]
},
{
"Description":"Remote Goal",
"Indicators":[
{
"Year":2018,
"Points":80857,
"Goal":"90000",
}
]
}
]
}
]
Here I need to change all the appearance of Year
property to 2017
, and all the appearance of Goal
property to: 50000
.
I'm thinking in having an array of objects where I can declare something like:
const newValues = [{property: 'Year', newValue: 2019}, {property: 'Goal', newValue: 50000}]
and then use it to compare iterating over the nested array of objects using filter
or reduce
? Any ideas or suggestions ?