Skip to content

Instantly share code, notes, and snippets.

@rjcorwin
Last active July 16, 2020 17:08
Show Gist options
  • Save rjcorwin/fad47709631510cfb3c883f336d650fe to your computer and use it in GitHub Desktop.
Save rjcorwin/fad47709631510cfb3c883f336d650fe to your computer and use it in GitHub Desktop.
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