Concatenating Objects / Cloning Object without referencing.
Mon Apr 17 2023 11:34:21 GMT+0000 (Coordinated Universal Time)
Saved by
@shahzaibtahamee
#javascript
const tempObj = {
prop1 : "value1",
prop2 : "value2"
}
//-----Concatinating / Adding New Key Values to Object--------//
Object.assign(tempObj,
{
"prop123" : "value123",
"prop456" : "value456"
},
{
"prop888" : "value888",
"prop090" : "value090"
}
)
//--------Cloning an Object---------------//
const clonedObject = Object.assign({}, tempObj)
clonedObject.prop1 = "newProperty" //it does not affect the original object
console.log(tempObj);
//console.log(clonedObject, tempObj);
//Find more in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
//-----------------------------------------------------------//
content_copyCOPY
Comments