Chrome Extension

How to Check if Arrays in a Object Are All Empty

var allEmpty = Object.keys(obj).every(function(key){
return obj[key].length === 0
})

//filter 
function isUnPopulatedObject(obj) { 
    return Object.keys( obj ).filter( function(key){
      return obj[ key ].length > 0;  //if any array has a property then filter will return this key.
    }).length == 0; //used == here since you want to check if all are empty
}

//every 
function isUnPopulatedObject(obj) { 
    return Object.keys( obj ).every( function(key){
      return obj[ key ].length == 0;  
    }); 
}

//some 
function isUnPopulatedObject(obj) { 
    return Object.keys( obj ).some( function(key){
      return obj[ key ].length > 0;  
    }) === false; 
}

//es8 
const objectIsEmpty = obj => Object.values(obj).every(
    val => Array.isArray(val) && val.length === 0
);

//every 2 sample 
function objectIsEmpty(obj) {
    return Object.keys(obj).every(key => 
      Array.isArray(obj[key]) && obj[key].length
    );
}
We are a bunch of lazy programmers so we developed this chrome extension
search code from your favorite search engine
Install Now
Output
How to Check if Arrays in a Object Are All Empty

How to Check if Arrays in a Object Are All Empty

Search Index Data (The code snippet can also be found with below search text)

How to Check if Arrays in a Object Are All Empty
Was this helpful?
0 Comments
Open Code Manager We are hiring