TIL: Object Spread Operator

December 11, 2015JavaScriptES6

The JavaScript spread operator is awesome! Previously when I wanted to merge two objects I would have to pull in underscore or lodash and do something like this.

var obj = _.extend(objectOne, objectTwo, {
  customProp: "You better believe it!",
});

But now with the help of the wonderful babel compiler (along with the stage-2 preset) I am able to do this for the same effect.

var obj = {
  ...objectOne,
  ...objectTwo,
  customProp: "You better believe it!",
};
The author, Jason Merino, with sun glasses and a hat

Jason Merino 💻 🚀

Software engineer, TypeScript enthusiast, avid gardener, all around family man, Franciscan at heart, celiac, aphantasiac. I enjoy nature and a good technical manual.

Follow me on Twitter and checkout my code on Github!