more details=>https://developer.mozilla.org/en-US/docs/Web/JavaScript
/Reference/Global_Objects/Object/assign
link is here:-https://stackblitz.com/edit/js-m4m1jh
/Reference/Global_Objects/Object/assign
link is here:-https://stackblitz.com/edit/js-m4m1jh
//using Object.assign() we can copy values from one object to
aonther object form source to target object and target object return
var objectA={
"name":"ObjectA",
"data":
{
"x":200,
"y":300
}
}
var objectB={
"name":"ObjectB",
"data":
{
"x":1200,
"y":1300
}
}
//objectB is source object
//objectA is target object
Object.assign(objectA,objectB);
//other example data added from seond object source object to
the target object and because the property name is different its copied as a
new prpoerty in objectA and if you try to use same property it would be
replaced
Object.assign(objectA,{data2:"copy me"})
console.log(objectA);
Comments
Post a Comment