laggingreflex laggingreflex - 1 year ago 95
Javascript Question

What has changed in Lodash from 3 to 4 that this code is not working?

I have a code like this:

const _ = require('lodash');

const fn = _.partialRight(_.pick, _.identity);

const x = { some: 'value', empty: null };

const y = fn(x);

console.log('x:', x);
console.log('y:', y);

is supposed to remove empty properties

Result with Lodash 3.10.1:

x: { some: 'value', empty: null }
y: { some: 'value' }

Result with Lodash 4.15.0:

x: { some: 'value', empty: null }
y: {}

What has changed in Lodash 4 that it's not working anymore?

Answer Source

change your const fn = _.partialRight(_.pick, _.identity) to const fn = _.partialRight(_.pickBy, _.identity);

_.pick used to be just one function but they broke it out into _.pick and _.pickBy in the latest updates. you would use _.pick when you are passing in known keys and _.pickBy when you are using a custom function to test if a key/value should be picked based on your own parameters,

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download