I'm trying to determine whether all arrays inside an object are empty. To illustrate, consider the following object:
var obj = {
arr1: [0, 1, 2],
arr2: [1, 2, 3],
arr3: [2, 3, 4]
};
After pop()
ing values from the arrays within the object, I need to verify if they are all empty.
One approach I've considered involves the following code snippet:
var isEmpty = true;
for (var item in obj) {
if (obj[item] !== 0) {
isEmpty = false;
}
}
// now isEmpty accurately indicates whether all arrays in the object are empty
However, I'm curious if there's a simpler and more direct solution available. I've searched for alternatives but answers like this one don't apply because it focuses on checking if the object itself is empty rather than the arrays within the object. My question is essentially the opposite of this one.