//判断对象为空对象 // 1. Object.keys() let obj = { } function getObjLength(){ console.log(Object.keys(obj).length === 0) //true } getObjLength() // 2.Object.entries() function isEmptyObj(){ console.log(Object.entries(obj).length=== 0)//true } isEmptyObj() //3.for..in function isEmpty(){ for (let i in obj){ if (obj.hasOwnProperty(i)) { return false; } } return true; } console.log(isEmpty())//true //4.JSON.stringify console.log(JSON.stringify(obj)=='{}') //true
标签:function,判断,obj,log,对象,Object,为空,console,true From: https://www.cnblogs.com/qinlinkun/p/18079783