function isObjectEmpty(obj) {
return Object.keys(obj).length === 0;
}
Object.keys(object).length === 0
const empty = {};
/* -------------------------
Plain JS for Newer Browser
----------------------------*/
Object.keys(empty).length === 0 && empty.constructor === Object
// true
/* -------------------------
Lodash for Older Browser
----------------------------*/
_.isEmpty(empty)
// true
function isEmpty(obj) {
return Object.keys(obj).length === 0;
}
// because Object.keys(new Date()).length === 0;
// we have to do some additional check
Object.keys(obj).length === 0 && obj.constructor === Object