JavaScript Compruebe si el objeto está vacío
function isObjectEmpty(obj) {
return Object.keys(obj).length === 0;
}
Grepper
function isObjectEmpty(obj) {
return Object.keys(obj).length === 0;
}
function isEmptyObject(obj) {
return !Object.keys(obj).length;
}
const empty = {};
/* -------------------------
Plain JS for Newer Browser
----------------------------*/
Object.keys(empty).length === 0 && empty.constructor === Object
// true
/* -------------------------
Lodash for Older Browser
----------------------------*/
_.isEmpty(empty)
// true
> !!Object.keys(obj).length;
Object.entries(objectToCheck).length === 0
function isEmpty(obj) { return Object.keys(obj).length === 0;}