Let’s talk about how js judges that the object is empty.

  javascript, question

图片描述

图片描述

This is my judgment method. Do you have any other judgment method?

Look at your definition of an empty object
If the interpretation object is undefined/null
Then use the if statement directly

var obj;
 if(!  obj){
 console.log("object is null or undefined");
 bracket

If you judge that the object does not have any attributes, this is not easy to do.
Use
for...inAbility to traverse enumerable attributes, including in prototype
Object.keys(ES2015)Value traverses its own enumerable property
However, the attribute of the object can also be set to enumerable=false as non-enumerable, so you cannot judge whether there is an attribute by the above method.

$.isEmptyObject();The method also checks enumerable properties

Therefore, the specific problems still need to be specifically analyzed, according to your business scenario
There are no special settings
$.isEmptyObject();
Object.keys()
for...in
Can be used