10
rated 0 times
[
17]
[
7]
/ answers: 1 / hits: 47480
/ 8 Years ago, mon, april 25, 2016, 12:00:00
I just started using lodash and have this array of objects, where one of the properties either has an integer or is null. I know how to filter the array for items that are null, but how do I check if it's not null?
Let's say I have something like this:
var users = [
{ 'user': 'barney', 'default': 1 },
{ 'user': 'dino', 'default': 0 },
{ 'user': 'wilma', 'default': 1 },
{ 'user': 'fred', 'default': null }
];
And then I want something like:
var notNullDefault = _.filter(sourceData, ['is_default', ! null ]); // objects with names barney, dino, wilma
var nullDefault = _.filter(sourceData, ['is_default', null ]); // object with name fred
Again, I'm new to lodash, so maybe there's a better way to accomplish this too.
Thanks in advance.
More From » arrays