Created
May 26, 2021 02:58
-
-
Save myogeshchavan97/5a9edb8acc91f8eb8689e5b8b3657107 to your computer and use it in GitHub Desktop.
Merge using spread operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const user = { | |
name: 'David', | |
phone: 122345678, | |
location: { | |
city: 'Camden', | |
country: 'UK' | |
} | |
}; | |
const updates = { | |
name: 'David', | |
phone: 123456789, | |
location: { | |
city: 'Smithfield' | |
} | |
}; | |
console.log({ ...user, ...updates }); | |
/* output: | |
{ | |
name: 'David', | |
phone: 123456789, | |
location: { | |
city: 'Smithfield' | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment