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