Pages

Showing posts with label lodash. Show all posts
Showing posts with label lodash. Show all posts

Lodash merge without overwriting

In many cases, you want to combine small objects into a big object. Lodash gives you _.merge() method to do so. (For more usages of _.merge(), see the lodash's docs).


let name = {name: 'Joe'},
    age = {age: 18},
    user = _.merge(name, age); // user = {name: 'Joe', age: 18}     

But what if you want to merge more than 2 objects together? Say, an array of objects? Well, remember apply method?