You can determine whether an object is an empty object in the following two ways:
1、Object.keys()
Get the attribute list of the object, and then determine whether the length of the list is 0
let obj = {};
if (Object.keys(obj).length === 0) {
console.log("空对象");
}
2、 for...in
Loop through the object. If there are attributes, it is not an empty object.
const obj = {};
let isEmpty = true;
for (let item in obj) {
isEmpty = false;
}
if (isEmpty) {
console.log("obj is empty");
}