Options
All
  • Public
  • Public/Protected
  • All
Menu

Module remove

Index

Functions Array

Array Functions

  • remove<T>(array: ArrayLike<T>, predicate: CollectionIteratee<T, boolean>): T[]
  • Removes all elements from array that predicate returns truthy for and returns an array of the removed elements. The predicate is invoked with three arguments: (value, index, array).

    Note: Unlike filter, this method mutates array. Use pull to pull elements from an array by value.

    since

    5.11.0

    see

    pull, pullAll, pullAllBy, pullAllWith, pullAt, reject, filter

    example
    const array = [1, 2, 3, 4]
    const evens = remove(array, n => n % 2 == 0)

    console.log(array)
    // => [1, 3]

    console.log(evens)
    // => [2, 4]

    Type Parameters

    • T

    Parameters

    • array: ArrayLike<T>

      The array to modify.

    • predicate: CollectionIteratee<T, boolean>

      The function invoked per iteration.

    Returns T[]

    Returns the new array of removed elements.