Skip to content

Function: isObject()

isObject(val): val is Record<string, unknown>

Type guard to check if a value is an object (excluding null). Note: This returns true for arrays, dates, regexes, and other object types. Use isPlainObject() for plain objects only.

Parameters

val

unknown

The value to check

Returns

val is Record<string, unknown>

True if the value is an object (not null)

Example

typescript
const values = [null, {}, [], new Date()]

values.forEach(val => {
  if (isObject(val)) {
    console.log('Is object:', val)
  }
})
// Output: 'Is object: {}', 'Is object: []', 'Is object: [Date]'

Released under the MIT License.