Function clearArray

  • Removes all elements from an array by mutating it in-place.

    Type Parameters

    • T extends unknown[]

    Parameters

    • array: undefined | null | T

      The array to clear.

    Returns T

    A new array containing the elements that were removed.

    Example

    Basic Usage

    const array = [1, 2, 3, 4, 5]
    const removed = clearArray(array)
    console.log(array, removed) // [] , [1, 2, 3, 4, 5]

    If there are no elements to remove, an empty array is returned.

    const array = []
    const removed = clearArray(array)
    console.log(array, removed) // [] , []
    console.log(array === removed) // false

Generated using TypeDoc