[js] 빈 객체 체크

moo·2023년 6월 13일
0

빈 객체 체크

// 객체 프로퍼티를 대상으로 반복문을 실행하다가 프로퍼티가 하나라도 있으면 그 즉시 false를 반환
function isEmpty(obj) {
  for (let key in obj) {
    // if the loop has started, there is a property
    return false;
  }
  return true;
}

출처
https://ko.javascript.info/object#ref-592

profile
front developer

0개의 댓글