Skip to content

Instantly share code, notes, and snippets.

@yurtarmehmet
Created December 27, 2020 07:37
Show Gist options
  • Save yurtarmehmet/253c03a87d7e8e25bdbb022c31e00135 to your computer and use it in GitHub Desktop.
Save yurtarmehmet/253c03a87d7e8e25bdbb022c31e00135 to your computer and use it in GitHub Desktop.
// COPYING OBJECTS
// foreach
const person = {name: "John", age: 30, children: [{name:"JOHNNY"}]};
const newPerson = {};
Object.keys(person).forEach((personField) => {
newPeople[personField] = person[personField]
});
// object assign
const newPerson = Object.assign({}, person);
// spread ...
const newPerson = {...person};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment