Function isPlainArray

  • Checks if a value passes Array.isArray and has prototype Array.prototype.

    Parameters

    • value: unknown

      The value to check.

    Returns value is unknown[]

    true if the check passes, false otherwise.

    Remarks

    This is useful for checking that the prototype of an array has not been modified. However, this will return false for arrays created in other realms since they will have a different prototype.

    Example

    Basic usage

    isPlainArray([]) // true
    isPlainArray(new Array()) // true

    isPlainArray(new Uint16Array()) // false
    isPlainArray(Object.create(Array.prototype)) // false
    isPlainArray(Object.create(null)) // false
    isPlainArray(null) // false

    Comparison with Array.isArray:

    class MyArray extends Array {}
    Array.isArray(new MyArray()) // true
    isPlainArray(new MyArray()) // false

Generated using TypeDoc