Function pullAll

  • Category

    Remove all elements equal to a given element from an array. Strict equality (===) is used to compare elements.

    Time complexity: O(n)

    Space complexity: O(n)

    Type Parameters

    • T

    Parameters

    • array: T[]

      The array to remove elements from

    • element: T

      The element to remove

    Returns ReturnType<typeof array["splice"]>

    The return value of Array.prototype.splice

    Array

    const array = [1, 1, 2, 2, 3, 3];

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

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