Update (February 08)
Since v4.0.1, _.omitBy and _.pickBy now provide a key parameter for the predicate. Therefore, the correct answer is:
Use _.pickBy(object, [predicate=_.identity])
Original answer
Starting with v4, some methods have been split. For example, _.pick () is broken into _.pick(array, [props]) and _.pickBy(object, [predicate=_.identity])
My first approach was trying to use this _.pickBy() method. Unfortunately, all methods ...By() are only passed as the first argument. They will not receive a key or collection. That's why this does not work, just switching from _.pick() to _.pickBy() .
However, you can do it as follows:
var thing = { "a": 123, "b": 456, "abc": 6789 }; var result = _.pick(thing, _(thing).keys().filter(function(key) { return _.startsWith(key, "a"); }).value()); console.log(result)
source share