我有一个名为 onversation
的变量,其中包含:
{
"conversationId": "adbabc54-3308-436d-a48b-932f4010d3c6",
"participantId": "415651e6-f0a5-4203-8019-4f88c3ed9cd5"
}
我还有一个名为 person
的对象,其中包含:
{
firstname: "fred",
surname: "smith",
age: "21",
gender: "male"
}
我想要一个名为 result
的组合对象,如下所示
result {
conversation {
conversationId : adbabc54-3308-436d-a48b-932f4010d3c6,
participantId : 415651e6-f0a5-4203-8019-4f88c3ed9cd5
},
person {
firstname: "fred",
surname: "smith",
age: "21",
gender: "male"
}
}
我将如何动态执行此操作,从而使用变量“对话”的名称和对象“人员”的名称构建结果对象?
此外,对话或人的长度可以是任意长度。 如果可能纯 JavaScript,但可以使用下划线等。
最佳答案
试一试
var result = {
'conversation': conversation,
'person': person
}
动态
var result = {}
result['person'] = person
或
resilt.person = person
关于JavaScript 构建动态对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40546625/