dropWhile source npm

_.dropWhile(array, [predicate=_.identity])

裁剪数组,起点从 predicate 返回假值开始。predicate 会传入3个参数:(value, index, array)。

参数

  1. array (Array)

    array 需要处理的数组

  2. [predicate=_.identity] (Function|Object|string)

    这个函数会在每一次迭代调用

返回值 (Array)

Returns the slice of array.

示例

var users = [
  { 'user': 'barney',  'active': false },
  { 'user': 'fred',    'active': false },
  { 'user': 'pebbles', 'active': true }
];

_.dropWhile(users, function(o) { return !o.active; });
// => 结果: ['pebbles']

// 使用了 `_.matches` 的回调处理
_.dropWhile(users, { 'user': 'barney', 'active': false });
// => 结果: ['fred', 'pebbles']

// 使用了 `_.matchesProperty` 的回调处理
_.dropWhile(users, ['active', false]);
// => 结果: ['pebbles']

// 使用了 `_.property` 的回调处理
_.dropWhile(users, 'active');
// => 结果: ['barney', 'fred', 'pebbles']