_.pick for collections (underline / lodash)

Is there a lodash function where you can create a collection from another by selecting only the specified attributes?

stats = [{a:1, b:1}, {a:2, b:2}] reducedStats = _.pick(stats, 'a'); // now is [{a:1},{a:2}] 

A regular pick only works for objects, not collections.

I achieved this with

 stats = stats.map(_.partialRight(_.pick, 'a')); 

which is somewhat detailed.

+7
source share
1 answer

In my example here, I add a method called make that performs your task.

 var _ = require('lodash'); _.make = (arr, ...args) => arr.map(obj => _.pick(obj, args)); 
+2
source share

All Articles