//判斷物件為空物件 // 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