Javascript判斷空物件
方法1:
const isEmpty = obj => {
var name
for (name in obj) {
return false
}
return true
}
複製程式碼
方法2:
const isEmpty = obj => {
return Object.keys(obj).length === 0 && obj.constructor === Object
}
複製程式碼
Javascript判斷空物件
const isEmpty = obj => {
var name
for (name in obj) {
return false
}
return true
}
複製程式碼
const isEmpty = obj => {
return Object.keys(obj).length === 0 && obj.constructor === Object
}
複製程式碼