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

    Function removeBy

    • Remove value by predicate function from array

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

      also see remove

      Type Parameters

      • T

      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
      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 }]