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β
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β
| Value | Result |
|---|---|
{} | 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
}
true
false