You can use several methods:
1. Using Object.keys()
const isEmpty = (obj) => {
return Object.keys(obj).length === 0 && obj.constructor === Object;
};
2. Using a for...in Loop
const isEmpty = (obj) => {
for (let prop in obj) {
if (obj.hasOwnProperty(prop)) {
return false;
}
}
return true;
};
3.Using JSON.stringify()
const isEmpty = (obj) => {
return JSON.stringify(obj) === '{}';
};