Function isPlainObject

  • Checks if a value has a prototype of Object.prototype or null. To disallow a null prototype, pass false to allowNullProto.

    Type Parameters

    • T

    Parameters

    • value: T

      The value to check.

    • allowNullProto: boolean = true

      Whether to allow a null prototype. Defaults to true.

    Returns value is T extends Function | readonly unknown[]
        ? never
        : T & object

    true if the check passes, false otherwise.

    Example

    Basic usage

    isPlainObject({}) // true
    isPlainObject(Object.create(Object.prototype)) // true
    isPlainObject(Object.create(null)) // true

    isPlainObject([]) // false
    isPlainObject(Object.create({})) // false

    class Foo {}
    isPlainObject(new Foo()) // false

    When allowNullProto is false:

    // previously returned true
    isPlainObject(Object.create(null), false) // false

Generated using TypeDoc