Skip to content

Instantly share code, notes, and snippets.

@Naedri
Last active August 25, 2022 22:03
Show Gist options
  • Save Naedri/3bbe7a3d0af6be05b61694e0fdd4e298 to your computer and use it in GitHub Desktop.
Save Naedri/3bbe7a3d0af6be05b61694e0fdd4e298 to your computer and use it in GitHub Desktop.
Objects concatenation with redondant values.
let obj1, obj2, obj3;
/**
* spread_synthax
*/
//with non redondant values, everyone stay
obj1 = { food: 'pizza', car: 'ford' };
obj2 = { animal: 'dog' };
obj3 = { ...obj1, ...obj2 };
console.log(obj3); // => { food: "pizza", car: "ford", animal: "dog" }
//with redondant values, the last stays
obj1 = { food: 'pizza', car: 'ford', animal: 'human' };
obj2 = { animal: 'dog' };
obj3 = { ...obj1, ...obj2 };
console.log(obj3); // => { food: "pizza", car: "ford", animal: "dog" }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment