Arnab
Arnab

Reputation: 2354

chaining in lodash / underscore ending with pull

I'm trying to learn chaining in lodash/underscore..

I found a nice chaining code here..

var xs = [{a: 1, b: 2}, {b: 3, c: 4, d: 5}];

console.log(JSON.stringify(
_(xs).map(_.keys).flatten().unique().value()));

Now, I would like to remove a value 'b' from the resultant array.

Without chaining I could have done the following..

_.pull(list, 'b'); // ['a', 'c', 'd']

What would I do if I wanted to continue the chain or is chaining only possible in specific conditions..

Thanks

Upvotes: 1

Views: 84

Answers (1)

Amit
Amit

Reputation: 46323

without looks like an obvious choice:

console.log(JSON.stringify(
  _(xs).map(_.keys).flatten().unique().without('b').value()));

Upvotes: 2

Related Questions