Is there a "better" way to check if an object has empty arrays (0-*) than this:
emptyArr: function() {
var obj = getObj();
return obj.abc.length == 0 || obj.def.length == 0 || obj.ghi.length == 0 || obj.jkl.length == 0 …………;
}
Edit: Here is how the object looks like:
- Object
- abc = []
- def = []
- ghi = []
- jkl = []
- …
I want to check if the object contains any empty arrays.
Any help would be greatly appreciated.
Is there a "better" way to check if an object has empty arrays (0-*) than this:
emptyArr: function() {
var obj = getObj();
return obj.abc.length == 0 || obj.def.length == 0 || obj.ghi.length == 0 || obj.jkl.length == 0 …………;
}
Edit: Here is how the object looks like:
- Object
- abc = []
- def = []
- ghi = []
- jkl = []
- …
I want to check if the object contains any empty arrays.
Any help would be greatly appreciated.
Share Improve this question edited Sep 15, 2014 at 19:32 user3475602 asked Sep 15, 2014 at 19:25 user3475602user3475602 1,2172 gold badges22 silver badges43 bronze badges 2- Could you give an example of how your object looks? – Afsa Commented Sep 15, 2014 at 19:28
- 1 Can't you loop through them and break out of loop as soon as you hit an empty array? – Huangism Commented Sep 15, 2014 at 19:34
1 Answer
Reset to default 5Is the question "Check if an object has any empty array members"?
If so:
function hasEmptyArrays(obj) {
var emptyArrayMembers = _.filter(obj, function(member) {
return _.isArray(member) && _.isEmpty(member)
});
return emptyArrayMembers.length > 0;
}