분류
javascript
Javascript 30초 Snippet - Type : isEmpty
본문
a 값이 빈 객체, 컬렉션이거나 열거 가능한 속성이 없거나 컬렉션으로 간주되지 않는 유형 인 경우 true를 반환합니다.
https://github.com/30-seconds/30-seconds-of-code
제공된 값이 null인지 또는 length가 0인지 확인하십시오.
const isEmpty = val => val == null || !(Object.keys(val) || val).length;
ex)
isEmpty([]); // true isEmpty({}); // true isEmpty(''); // true isEmpty([1, 2]); // false isEmpty({ a: 1, b: 2 }); // false isEmpty('text'); // false isEmpty(123); // true - type is not considered a collection isEmpty(true); // true - type is not considered a collection
- 이전글Javascript 30초 Snippet - Type : isFunction 19.11.25
- 다음글Javascript 30초 Snippet - Type : isBoolean 19.11.25