let course = {
name: 'Angular',
};
let newCourse= Object.assign({}, course);
newCourse.name= 'React';
console.log(course.name); // writes Angular
console.log(newCourse.name); // writes React
For Nested Object we can use of 3rd party libraries, for deep copying objects. In case of lodash, use _.cloneDeep()let newCourse= _.cloneDeep(course);
https://stackoverflow.com/questions/39506619/angular2-how-to-copy-object-into-another-object/44199667
No comments:
Post a Comment