To check if an object is empty in Javascript:
Object.getOwnPropertyNames(obj).length === 0;
Where obj is the object you’re testing e.g.:
var obj = {};
Object.getOwnPropertyNames(obj).length === 0; //true
obj = {'not' : 'empty'};
Object.getOwnPropertyNames(obj).length === 0; //false
Or to wrap it in a function:
function isEmpty(obj){
return (Object.getOwnPropertyNames(obj).length === 0);
}
This only works in ECMAScript 5 compatible browsers, so is useful when developing mobile / desktop web apps.