0

How to pick multiple properties from an array using only underscorejs ?

var arr = [{Analytics:16}, {Technology:12}, {Medical:20}, {Operations:40}]

Output i required in the below format. [12,40,20,16]

Thanks

1
  • How to get only specific value from an array. Example, i need only "Medical" value i.e, [20] Commented Aug 17, 2016 at 19:21

3 Answers 3

1

You could first map over the array and get the values and then flatten the result:

var result = _.flatten(_.map(arr, _.values));
Sign up to request clarification or add additional context in comments.

Comments

0
var arr = [{Analytics:16}, {Technology:12}, {Medical:20}, {Operations:40}];
var output = [];

_.each(arr, function (e){output.push(_.flatten(e)[0])});

output = [16, 12, 20, 40];

2 Comments

How to get only specific value from an array. Example, i need only "Medical" value i.e, [20]
_.reject(_.pluck(arr, "Medical"), function(val){ return _.isUndefined(val) }) for getting medical
0
var arr = [{Analytics:16}, {Technology:12}, {Medical:20}, {Operations:40}];
_.map(arr,function(m){return _.values(m)[0]});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.