I'm using _.pluck() from lodash to get the value of the keys from an array.
var employees = [
{
Name : "abc"
},
{
Name : "xyz"
}
]
var res = _.pluck(employees, 'Name');
Variable res would contain ['abc,'xyz']
When I do a search for some other field field
var res = _.pluck(employees, 'SomeRandomField');
Result - [undefined, undefined]
How can I get the above result just as null of undefined instead of an array of undefined values
Plnkr : http://plnkr.co/edit/qtmm6xgdReCuJP5fm1P2?p=preview
You can use filter
and pluck
:
var res = _.filter(_.pluck(employees, 'Name'), function(item) {
return item;
});
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