> For the complete documentation index, see [llms.txt](https://lodash.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lodash.shujuwajue.com/array/dropwhile.md).

# \_.dropWhile（开头丢掉元素）

**语法：**

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

**源代码链接：**[source](https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L7167)

**npm包链接：**[npm package](https://www.npmjs.com/package/lodash.dropwhile)

**描述：**

创建一个切片数组，去除array中从开头开始到 predicate 返回假值结束部分。predicate 会传入3个参数： (value, index, array)。

**开始版本：**&#x33;.0.0

**参数：**

* `array (Array)`: 需要处理的数组。
* `[predicate=_.identity] (Function)`: 每个迭代函数调用。&#x20;

**返回值：**

* `array (Array)`: 返回切片后新数组。

**例子：**

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

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

// The `_.matches` iteratee shorthand.
_.dropWhile(users, { 'user': 'barney', 'active': false });
// => objects for ['fred', 'pebbles']

// The `_.matchesProperty` iteratee shorthand.
_.dropWhile(users, ['active', false]);
// => objects for ['pebbles']

// The `_.property` iteratee shorthand.
_.dropWhile(users, 'active');
// => objects for ['barney', 'fred', 'pebbles']
```

> 解析：经过看官方的列子，一脸萌比，主要是官方的注释太迷惑（objects for），后来自己执了下结果后官方提供的结果不同，使用版本为lodash\@4.17.11.
>
> 下面的例子结果应该更好理解一下，只是从数组的后面开始进行判断，知道返回false结束。
>
> ```javascript
> var users = [
>   { 'user': 'barney',  'active': true },
>   { 'user': 'fred',    'active': false },
>   { 'user': 'pebbles', 'active': false }
> ];
>  
> _.dropRightWhile(users, function(o) { return !o.active; });
> [ { user: 'pebbles', active: true } ]
>  
> // The `_.matches` iteratee shorthand.
> _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
> // => [ { user: 'fred', active: false },{ user: 'pebbles', active: true } ]
>  
> // The `_.matchesProperty` iteratee shorthand.
> _.dropRightWhile(users, ['active', false]);
> // => [ { user: 'pebbles', active: true } ]
>  
> // The `_.property` iteratee shorthand.
> _.dropRightWhile(users, 'active');
> // [ { user: 'barney', active: false },{ user: 'fred', active: false },{ user: 'pebbles', active: true } ]
> ```

注意：不同的方式代表：`_.matches`，`_.matchesProperty`，`_.property`的简写法

## 资料

[lodash.js源码-dropWhile](https://segmentfault.com/a/1190000014724257)
