Function castArray

  • Casts value as an array if it's not one.

    Type Parameters

    • T extends any[]

    Parameters

    • array: T

    Returns T

    Returns the cast array.

    5.0.0

    castArray(1)
    // => [1]

    castArray({ 'a': 1 })
    // => [{ 'a': 1 }]

    castArray('abc')
    // => ['abc']

    castArray(null)
    // => [null]

    castArray(undefined)
    // => [undefined]

    castArray()
    // => []

    const array = [1, 2, 3]
    console.log(castArray(array) === array)
    // => true