Function: isPlainObject()
isPlainObject(
val
):val is object
Type guard to check if a value is a plain object (created by {} or new Object()). Unlike isObject(), this excludes arrays, dates, regexes, and other object types.
Parameters
val
unknown
The value to check
Returns
val is object
True if the value is a plain object
Example
typescript
const values = [{}, [], new Date(), Object.create(null)]
values.forEach(val => {
if (isPlainObject(val)) {
console.log('Plain object:', val)
}
})
// Output: 'Plain object: {}'