Is Empty

isEmpty tells you whether a value is empty.


Check if a value is empty

isEmpty returns true for:

  • null and undefined
  • An empty string ('')
  • An empty array ([])
  • An empty object ({})
  • A Map, Set, File, Blob or URLSearchParams with nothing in it
main.js
// Before
if (
value === null ||
value === undefined ||
value.length === 0 ||
Object.keys(value).length === 0
) {
// ...
}
main.js
// After
if (isEmpty(value)) {
// ...
}