Script/Javascript
자바스크립트 빈값체크, isEmpty, isNotEmpty, null체크
애플 로그
2021. 6. 21. 14:37
반응형
자바스크립트 빈값체크, isEmpty, isNotEmpty, null체크
java 에서와 같이 ( apache common Lib를 보면) isEmpty, isNotEmpty 함수를 만들어 쓰면 참 편하겠다
라는 생각이 들었다.
javascript 에서도 아래와 같이 빈값 여부를 체크해서 true, flase로 리턴하는 함수를 만들어 사용하면
편하지 않을까 생각이 든다.
var commonUtil =
{
isEmpty : function ( str )
{
return (str == '' || str == undefined || str == null || str == 'null' );
},
isNotEmpty : function(str)
{
return !this.isEmpty(str);
}
};
commonUtil.isEmpty(''); // true
commonUtil.isEmpty('123123'); // false
commonUtil.isNotEmpty('123123'); // true