• Category

    Remove an element from an array.

    Time complexity: O(n)

    Space complexity: O(n)

    Type Parameters

    • T

    Parameters

    • array: T[]

      The array to remove an element from

    • element: T

      The element to remove

    Returns ReturnType<typeof array["splice"]>

    The return value of Array.prototype.splice

    Array

    Example

    const array = [1, 2, 3];

    pull(array, 2); // [2]
    console.log(array); // [1, 3]

    pull(array, 2); // []
    console.log(array); // [1, 3]