【发布时间】:2019-03-27 16:41:00
【问题描述】:
我有两个对象,一个用于更新另一个,类似于 ETL Process。
const currentObject = {
myObject : [
{
'attribute1':'foo1',
'attribute2':'bar1',
'attribute3':'test1'
},
{
'attribute1':'foo2',
'attribute2':'bar2',
'attribute3':'test2'
},
{
'attribute1':'foo3',
'attribute2':'bar3',
'attribute3':'test3'
},
]
}
如果attribute3的值为“test1”,则转到另一个对象并检查test1属性并将currentObject替换为新值
const updateObject = {
myObject : {
'test1':'newtest1',
'test2':'newtest2',
'test3':'newtest3'
}
}
对 currentObject 属性进行更新需要使用 updateObject 属性作为参考; 其中 currentObject attribute1="test1" 应该从 updateObject test1 复制数据,依此类推:
最终值应该是这样的:
const currentObject = {
myObject : [
{
'attribute1':'foo1',
'attribute2':'bar1',
'attribute3':'newtest1'
},
{
'attribute1':'foo2',
'attribute2':'bar2',
'attribute3':'newtest2'
},
{
'attribute1':'foo3',
'attribute2':'bar3',
'attribute3':'newtest3'
}
]
}
【问题讨论】:
-
你有一个代码 sn-p 你试图实现它吗?
标签: javascript object ecmascript-6