uh_uqq
Last Updated: February 25, 2016
·
1.36K
· 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();

console.log(options);  
// Object {something: "nothing", nothing: "else", start: "start"}