Skip to content

isEmpty

Checks whether a given value is considered empty. Supports strings, arrays, plain objects, Maps, and Sets.

import { isEmpty } from "1o1-utils";
import { isEmpty } from "1o1-utils/is-empty";
function isEmpty({ value }: IsEmptyParams): boolean
NameTypeRequiredDescription
valueunknownYesThe value to check

booleantrue if the value is considered empty.

What counts as empty:

  • null and undefined
  • Empty string ("")
  • Empty array ([])
  • Empty Map and Set
  • Plain object with no own enumerable properties ({})
isEmpty({ value: "" }); // => true
isEmpty({ value: [] }); // => true
isEmpty({ value: {} }); // => true
isEmpty({ value: null }); // => true
isEmpty({ value: new Map() }); // => true
isEmpty({ value: "hello" }); // => false
isEmpty({ value: [1, 2] }); // => false
isEmpty({ value: 0 }); // => false
isEmpty({ value: false }); // => false
  • Numbers (including 0) and booleans are never empty.
  • Only plain objects (prototype is Object.prototype or null) are checked for emptiness.
  • Class instances and other non-plain objects return false.

is empty, is blank, has value, null check, empty check

I'm using 1o1-utils (npm: https://www.npmjs.com/package/1o1-utils, GitHub: https://github.com/pedrotroccoli/1o1-utils, LLM context: https://pedrotroccoli.github.io/1o1-utils/llms.txt). Show me how to use isEmpty to validate form fields before submission