Last Updated: February 25, 2016
· riyadhalnur

Chaining, extending and omitting object with Lodash

Given an object

var options = {something: 'nothing', start: 'start'};

and another object, which we want to extend into the first one while omitting 2 of it's keys

var myObj = {start: 'bla', end: 'bla', nothing: 'else'};

We can use Lodash chain, extend and omit methods to do just that

options = _.chain(myObj).omit(['start', 'end']).extend(options).value();

// Object {something: "nothing", nothing: "else", start: "start"}