Last active
July 16, 2020 17:08
-
-
Save rjcorwin/fad47709631510cfb3c883f336d650fe to your computer and use it in GitHub Desktop.
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 first = { | |
foo: 1, | |
bar: 1 | |
} | |
// Copy the first object into a new one and override the bar property. This is useful when you | |
// want to make a copy of a complex object and want to override just one particular part of it. | |
const second = { | |
...first, | |
bar: 2 | |
} | |
console.log(first) | |
/* | |
Output is... | |
{ | |
foo: 1, | |
bar: 1 | |
} | |
*/ | |
console.log(second) | |
/* | |
Output is... | |
{ | |
foo: 1, | |
bar: 2 | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment