I have the following object
{one : 1, two : 2, three : 3}
and I would like
[1,2]
Here my code
_.map({one : 1, two : 2, three : 3}, function(num, key){
if (key==='one' || key==='two') {
return num;
}
}); // [1, 2, undefined]
Actually I would like [1,2]
How can I improve my code?
thanks
You actually want to use _.pick
and _.values
:
_.values( _.pick( obj, "one", "two" ) )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With