@pengzhanbo/utils - v3.7.3
    Preparing search index...

    Function removeBy

    • Remove value by predicate function from array

      通过 predicate 方法,从数组中移除值

      Type Parameters

      • T

        The type of elements in the array / 数组元素的类型

      Parameters

      • array: T[]

        the array / 数组

      • predicate: (item: T, index: number, array: readonly T[]) => boolean

        the predicate function / 谓词函数

      Returns boolean

      if true, the value is removed, false otherwise. / 如果成功移除,返回 true, 否则返回 false

      This function mutates the original array in place. It uses Array.prototype.splice to remove the element.

      此函数会直接修改原数组。它使用 Array.prototype.splice 移除元素。

      also remove

      const arr = [1, 2, 3]
      removeBy(arr, n => n === 2) // => true
      console.log(arr) // => [1, 3]
      const arr = [
      { id: 1, csv: 1 },
      { id: 2, csv: 1 },
      { id: 3, csv: 1 },
      ]
      removeBy(arr, item => item.id === 2) // => true
      console.log(arr) // => [{ id: 1, csv: 1 }, { id: 3, csv: 1 }]