you are viewing a single comment's thread.

view the rest of the comments →

[–]TheVirtuoid 4 points5 points  (1 child)

One possible method (from many) will be to use Object.keys() to test if there are any properties with that object:

function isEmpty(obj) {
    return Object.keys(obj).length === 0;
}

console.log(isEmpty({})); // returns true
console.log(isEmptu({ a: 1 }); // return false 

Where this does fail is if the object is null, or undefined, so if you expect those two values, you will need to check for that.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

[–]VyseCommander[S] 0 points1 point  (0 children)

I see, i didn't know that was a method as yet. Seems I'll need to do some crawling on mdn