Skip to main content

isObject()

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

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

note

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
{}checkmark true
[]checkmark true
new Date()checkmark true
new Map()checkmark true
() => {}cross false
nullcross false
'string'cross 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
}