Answers for "An object clone copy"

12

copy object javascript

var x = {myProp: "value"};
var y = Object.assign({}, x);
Posted by: Guest on March-08-2020
0

javascript clone object

// syntax: let <newObjectName> = {...<initialObjectName>};

// example: 
const me = {
  name: 'Jakes',
  age: 30,
};
const friend = {...me};
friend.age = 27;
console.log(friend.age); // 27
console.log(me.age); // 30

// -----------------------------
//  BAD
// -----------------------------
const me = {
  name: 'Jonas',
  age: 30,
};
const friend = me;
friend.age = 27;
console.log(friend.age); // 27
console.log(me.age); // 30
Posted by: Guest on December-08-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language