Function isPlainObject

  • Checks to see if the past value is a plain object (not a class/array) value. Object are considered to be "plain" if they are created with no prototype Object.create(null) or by using the Object global (native) function, all other "objects" ar

    Parameters

    • value: any

      The value to check

    Returns value is object

    true if value is a normal plain object

    Since

    0.4.4

    Example

    console.log(isPlainObject({ 0: 'a', 1: 'b', 2: 'c' }));      // true
    console.log(isPlainObject({ 100: 'a', 2: 'b', 7: 'c' })); // true
    console.log(isPlainObject(objCreate(null))); // true

    const myObj = objCreate({}, {
    getFoo: {
    value() { return this.foo; }
    }
    });
    myObj.foo = 1;
    console.log(isPlainObject(myObj)); // true

    console.log(isPlainObject(['a', 'b', 'c'])); // false
    console.log(isPlainObject(new Date())); // false
    console.log(isPlainObject(new Error("An Error"))); // false
    console.log(isPlainObject(null)); // false
    console.log(isPlainObject(undefined)); // false
    console.log(isPlainObject("null")); // false
    console.log(isPlainObject("undefined")); // false
    console.log(isPlainObject("1")); // false
    console.log(isPlainObject("aa")); // false