我卡在一个问题上,试图改变嵌套对象数组中 特定 属性的值:
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",
}
]
}
]
}
]
我需要将Year
属性的所有外观更改为2017
,并且将Goal
属性的所有外观更改为:50000
。
我考虑使用一个对象数组来声明类似于:
const newValues = [{property: 'Year', newValue: 2019}, {property: 'Goal', newValue: 50000}]
然后使用它来比较使用
filter
或reduce
迭代嵌套的对象数组?有什么想法或建议吗?