js如何判断一个对象是否为空对象
方法1
let obj1 = {}
let obj2 = {a:1}
function func(obj)
{
for(let key in obj)
return false
return true
}
console.log(func(obj1))
console.log(func(obj2))
方法2
let obj1 = {}
let obj2 = {a:1}
function func(obj)
{
if(Object.keys(obj).length === 0)
return true
return false
}
console.log(func(obj1))
console.log(func(obj2))
方法3
let obj1 = {}
let obj2 = {a:1}
function func(obj)
{
if(JSON.stringify(obj) === '{}')
return true
return false
}
console.log(func(obj1))
console.log(func(obj2))
这是我的签名