773 B
773 B
title, tags, expertise, cover, firstSeen, lastUpdated
| title | tags | expertise | cover | firstSeen | lastUpdated |
|---|---|---|---|---|---|
| Collection is empty | type,array,object,string | beginner | blog_images/book-chair.jpg | 2018-01-23T19:25:17+02:00 | 2020-10-20T23:02:01+03:00 |
Checks if the a value is an empty object/collection, has no enumerable properties or is any type that is not considered a collection.
- Check if the provided value is
nullor if itslengthis equal to0.
const isEmpty = val => val == null || !(Object.keys(val) || val).length;
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