Skip to content

isPlainObject

Checks if a value is a plain object.

A plain object is created by {}, new Object(), or Object.create(null). Returns false for arrays, Date, Map, Set, RegExp, class instances, etc.

Available since v2.0.0

import { isPlainObject } from '@helpers4/guard';
// or, from the all-in-one package (same code, one install):
import { isPlainObject } from 'helpers4/guard';
isPlainObject(value: unknown): value is Record<string, unknown>
ParameterTypeDescription
valueunknownThe value to check

value is Record<string, unknown> — True if value is a plain object

isPlainObject({})           // => true
isPlainObject({ a: 1 })    // => true
isPlainObject(new Date())  // => false
isPlainObject([])          // => false
isPlainObject(null)        // => false

View source on GitHub