https://heedipro.tistory.com/172
자바스크립트에서 객체에 어떠한 속성이 들어가있지 않은 빈 객체인 경우
객체가 비어있는지 확인하는 방법을 알고 싶다.
var obj = {};
상식적으로는 비어있는 객체라면
우리는 비어있다 = null 이라고 생각해
obj == null 이렇게 확인해볼것이다.
그런데
이 방법 안돼안돼 ~
통하지 않는다.
그래서 확인하는 방법은 이렇게 2가지가 있다.
function isEmpty(obj) {
return Object.keys(obj).length === 0;
}
function isEmpty(obj) {
for(var prop in obj){
if(obj.hasOwnProperty(prop))
return false;
}
return true;
}