GuobaGuoba Utils

isEmpty

@guoba-ai/utils / guard / isEmpty

Function: isEmpty()

function isEmpty(val): boolean;

Defined in: guard.ts:197

Check if a value is empty. Returns true for:

  • null and undefined
  • Empty strings ('')
  • Empty arrays ([])
  • Empty objects ({})

Parameters

val

unknown

The value to check

Returns

boolean

true if the value is considered empty

Example

isEmpty([]) // true

isEmpty({}) // true

isEmpty('') // true

isEmpty(null) // true

isEmpty(new Map([['key', 'value']])) // true

isEmpty([1]) // false

isEmpty(0) // false

Warning

Map, Set, Date, and other objects without enumerable own keys are considered empty.

On this page