Last active
May 30, 2018 11:47
-
-
Save davidchase/5948553 to your computer and use it in GitHub Desktop.
Plain javascript gut check if object is empty or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var yourObjectHere = {}; | |
Object.getOwnPropertyNames(yourObjectHere).length === 0; // empty object true | |
var yourObjectHere = {'empty':'i am not empty!!'}; | |
Object.getOwnPropertyNames(yourObjectHere).length === 0; // empty object false | |
// function isEmpty(obj) with object param | |
var isEmpty = function(yourObjectHere) { | |
for (var key in yourObjectHere) return false; return true; | |
} | |
// empty object will return false and vice versa |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment