Q:

javascript how to check for an empty object

function isObjectEmpty(obj) {
    return Object.keys(obj).length === 0;
}
26
function isEmptyObject(obj) {
    return !Object.keys(obj).length;
}
5
> !!Object.keys(obj).length;
1
// because Object.entries(new Date()).length === 0;
// we have to do some additional check
Object.entries(obj).length === 0 && obj.constructor === Object
7
JSON.stringify({}) !== '{}';
-1

New to Communities?

Join the community