我有这个对象:
let ob1 = {
"2021-08-10": {
"A0304": {
"48": 1000
},
"A0301": {
"4": 1000,
"30": 1000,
"40": 1000
}
},
"2021-08-11": {
"A0301": {
"4": 1000
}
}
}
,我想插入另一个对象,比如
"2021-08-13": {"A0301": {4: 1000}
使用
let new = {'2021-08-13': {'A0301': { 4: 'Hallo'}}};
Object.assign(obj1,new);`
工作好。但我想把它改成动态的,比如:
let new = {app.desire.date: {app.desire.slot: { app.desire.slot: 'Hallo'}}};
但是通过定义new,我得到错误:Uncaught SyntaxError: missing: after property id
怎么做呢?
尝试使用[app.desire.date]
let obj1 = {
"2021-08-10": {
"A0304": {
"48": 1000
},
"A0301": {
"4": 1000,
"30": 1000,
"40": 1000
}
},
"2021-08-11": {
"A0301": {
"4": 1000
}
}
}
const newNode = { '2021-08-13': { 'A0301': { 4: 'Hallo' } } };
Object.assign(obj1, newNode);
var app = {
desire: {
date: '2021-08-14',
slot: 'A0301',
key: 4
}
}
let newNode2 = {
[app.desire.date]: {
[app.desire.slot]: {
[app.desire.key]: 'Hallo'
}
}
};
Object.assign(obj1, newNode2);
console.log(obj1)