I would like to combine topData and bottomData into completeData.
var topData = {
"auth": "1vmPoG22V3qqf43mPeMc",
"property" : "ATL-D406",
"status" : 1,
"user" : "[email protected]",
"name" : "Abraham Denson"
}
var bottomData = {
"agent" : "[email protected]",
"agency" : "Thai Tims Agency",
"agentCommission" : 1000,
"arrival" : "arrive 12pm at condo",
"departure" : "leaving room at 6pm",
}
var completeData = topData.concat(bottomData)
Since these are not arrays, concat wont work here.
Can this be done without making foreach loops?
You can use Object.assign()
to concatenate your objects.
var newObj = Object.assign({}, topData, bottomData)
From 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" : "[email protected]",
"name" : "Abraham Denson"
}
var bottomData = {
"agent" : "[email protected]",
"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);
You can use Object.assign.
var topData = {
"auth": "1vmPoG22V3qqf43mPeMc",
"property": "ATL-D406",
"status": 1,
"user": "[email protected]",
"name": "Abraham Denson"
}
var bottomData = {
"agent": "[email protected]",
"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)
bottomData
will be added to topData
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With