DEV Community

bomoniyi
bomoniyi

Posted on

Using Object spread to merge objects

const user = {
  name: "",
  username: "",
  phoneNumber: "",
  email: "",
  password: "",
  verified: true 
};

const newUser = {
  username: "ReedBarger",
  email: "reed@gmail.com",
  password: "mypassword"  
};

const createdUser = { ...user, ...newUser, verified: false };
console.log(createdUser);
// console.log(Object.assign({}, user, newUser, { verified: false }));

Enter fullscreen mode Exit fullscreen mode

Top comments (0)