An easy guide to object rest/spread properties in JavaScript

Merging multiple JavaScript objects is a frequent task. Unfortunately JavaScript is sloppy at providing a convenient syntax to do the merge. At least until now.

In ES5 your solution is _.extend(target, [sources]) from Lodash (or any alternative), and ES2015 introduces Object.assign(target, [sources]).

Luckily object spread syntax (an ECMASript proposal at stage 3) is a step forward how to manipulate objects, providing a short and easy to follow syntax.

https://dmitripavlutin.com/object-rest-spread-properties-javascript/

Advertisements