How to merge two objects?
How to make deep copy of object?
Object.assign lets us merge one object's properties into another, replacing values of properties with matching names. We can use this to copy an object's values without altering the existing one.
let movie1 = {
name: 'Star Wars',
episode: 7
};
let movie2 = Object.assign({}, movie1);
movie2.episode = 8;
console.log(movie1.episode); // writes 7
console.log(movie2.episode); // writes 8
How to make deep copy of object?
Object.assign lets us merge one object's properties into another, replacing values of properties with matching names. We can use this to copy an object's values without altering the existing one.
let movie1 = {
name: 'Star Wars',
episode: 7
};
let movie2 = Object.assign({}, movie1);
movie2.episode = 8;
console.log(movie1.episode); // writes 7
console.log(movie2.episode); // writes 8
No comments:
Post a Comment