Skip to content

remove

js
_.remove(array, [predicate=_.identity])

array 中删除所有 predicate 返回真值的元素,并返回已删除元素的数组。使用三个参数调用谓词:(value, index, array)。

¥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).

注意:与 _.filter 不同,此方法会改变 array。使用 _.pull 按值从数组中提取元素。

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

新增于

¥Since

2.0.0

参数

¥Arguments

  1. array (数组):要修改的数组。

    ¥array (Array): The array to modify.

  2. [predicate=_.identity] (函数):每次迭代调用的函数。

    ¥[predicate=_.identity] (Function): The function invoked per iteration.

返回

¥Returns

(数组):返回已删除元素的新数组。

¥(Array): Returns the new array of removed elements.

示例

¥Example

js
var array = [1, 2, 3, 4];
var evens = _.remove(array, function(n) {
  return n % 2 == 0;
});

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

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

Lodash v4.17 中文网 - 粤ICP备13048890号