isPojo
isPojo(
value):value is Record<string, unknown>
Defined in: packages/core/src/guards/is-pojo.ts:33
Check whether a value is a Plain Old JavaScript Object — a data bag rather than an instance of something.
True when the value was built by {}, new Object() or
Object.create(null), and also when it merely inherits from such an
object, because the test follows the prototype chain. A Date, a Map, an
Error, an array and a class instance all fail.
Reach for it before any operation that treats an object as nothing but its
own keys — merging, cloning, deep equality. Walking a Date’s own keys finds
none and silently discards its value, so this guard is what keeps those
operations honest.
Object.create({}) passes here and fails hasObjectPrototype; see
isObject for the whole family and which question each one answers.
Because the check reads value.constructor, a data bag from another realm
(an iframe, a vm context) fails.
Parameters
Section titled “Parameters”unknown
The value to check
Returns
Section titled “Returns”value is Record<string, unknown>
True if the value is a POJO
Example
Section titled “Example” isPojo({ a: 1 }); // true isPojo(Object.create(null)); // true isPojo(Object.create({})); // true — the chain reaches Object.prototype isPojo(new Date()); // false isPojo([]); // false ```;