如何将对象属性添加到数组中的现有对象?

时间:2019-07-10 19:39:29

标签: javascript arrays ecmascript-6

试图将新对象推入对象数组,并抛出未定义的异常,这是怎么实现的?

main.js

let array = [{name: "abc", PrimaryAcc: { test: 'test'}}];
// contains any empty object
 const secondaryAcc =  {
        'copayEmployer': '0.00'
 };

array.map(obj=> ({ ...obj, SecondaryAcc: secondaryAcc }));

 console.log(array);

预期输出

[{name: "abc", PrimaryAcc: { test: 'test'}, SecondaryAcc: {
            'copayEmployer': '0.00'
     } }];

0 个答案:

没有答案