웹 개발

javascript] json isEmpty (빈 오브젝트인지 검사 empty object)

노루아부지 2019. 8. 23. 22:41

var json_object = {}

var json_array = []

 

json_array의 경우는 비어있는지 체크할 때 json_array.length 가 0인지 체크하면 되지만

json_object의 경우는 length를 사용하면 제대로 된 결과를 얻을 수 없다.

 

이 경우 jquery에서 제공해 주는

 

isEmptyObject()를 사용하면 된다.

 

출처 : http://api.jquery.com/jQuery.isEmptyObject/

 

1. 리턴 값

비어있는 object이면 true를 리턴

 

2. 사용법

if(jQuery.isEmptyObject(json_object)) {
	// 비어 있을 경우
}

if(true === jQuery.isEmptyIObject(json_object)) {
	// 비어 있을 경우
}

 

728x90
loading