我想将 topData 和 bottomData 合并为 completeData。
var topData = {
"auth": "1vmPoG22V3qqf43mPeMc",
"property" : "ATL-D406",
"status" : 1,
"user" : "test001@aaa.com",
"name" : "Abraham Denson"
}
var bottomData = {
"agent" : "pusher@agent.com",
"agency" : "Thai Tims Agency",
"agentCommission" : 1000,
"arrival" : "arrive 12pm at condo",
"departure" : "leaving room at 6pm",
}
var completeData = topData.concat(bottomData)
因为这些不是数组,concat 在这里不起作用。
这可以在不进行 foreach 循环的情况下完成吗?
您可以使用 Object.assign()
连接您的对象。
var newObj = Object.assign({}, topData, bottomData)
来自 MDN :
The Object.assign()
method is used to copy the values of all
enumerable own properties from one or more source objects to a target
object. It will return the target object.
var topData = {
"auth": "1vmPoG22V3qqf43mPeMc",
"property" : "ATL-D406",
"status" : 1,
"user" : "test001@aaa.com",
"name" : "Abraham Denson"
}
var bottomData = {
"agent" : "pusher@agent.com",
"agency" : "Thai Tims Agency",
"agentCommission" : 1000,
"arrival" : "arrive 12pm at condo",
"departure" : "leaving room at 6pm",
}
var completeData = Object.assign({}, topData, bottomData);
console.log(completeData);