Aller au contenu principal

isObject()

isObject(value): value is Record<string, any>

Checks if a value is an object (excluding null and arrays).

remarque

Excludes null and arrays. Includes plain objects, class instances, Map, Set, Date, etc.


Parameters

value: unknown

The value to check.


Returns: value is Record<string, any>

true if the value is an object, false otherwise.


See Also

isPlainObject


Since

1.0.0


Example

isObject({});           // => true
isObject({ a: 1 }); // => true
isObject(new Map()); // => true
isObject(new Date()); // => true
isObject([]); // => false
isObject(null); // => false
isObject('string'); // => false

How it works?

Type guard that checks if a value is an object (not null).

Type Narrowing

Common Checks

ValueResult
{} true
[] true
new Date() true
new Map() true
() => {} false
null false
'string' false

vs isPlainObject


Use Cases

Check for object types 📌

Generic check for any object type (including arrays, dates, etc.). Useful as a broad check before specific type narrowing.

if (isObject(value)) {
// value is object type
}