How to copy all properties from one source objects to a target object
Posted By : Priya verma | 30-Dec-2016
The Object.assign() method is used to copy the values of source objects to target object without any referencing.
Syntax:
Object.assign(target, ...sources)
Parameters
Target: The target object.
Sources: The source object(s).
Return value : The target object.
Example :
let obj1 = { a: 1 };
let obj2 = Object.assign({}, obj);
console.log(obj2); // Output :{ a :1}
// Merge an object
let first = {name: '/abc'};
let last = {lastName: '1'};
let person = Object.assign(first, last);
console.log(person); // {name: 'abc’, lastName: '1'}
THANKS
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Priya verma
Priya is a bright UI designer, having skills in , HTML, CSS, javascript, bootstrap. Her hobbies are playing outdoor games.