> 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/collection/every.md).

# \_.every（断言数组或对象中的值）

**语法：**

```javascript
_.every(collection, [predicate=_.identity])
```

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

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

**描述：**

通过`predicate`（断言函数） 检查`collection`（集合）中的**所有**元素是否都返回真值。一旦`predicate`（断言函数） 返回假值，迭代就马上停止。`predicate`（断言函数）调用三个参数：*(value, index|key, collection)*。

> **注意:**&#x8FD9;个方法对于对于[空集合](https://en.wikipedia.org/wiki/Empty_set)返回`true`，因为空集合的[任何元素都是 true](https://en.wikipedia.org/wiki/Vacuous_truth)。

**开始版本：**&#x30;.1.0

**参数：**

* `collection (Array|Object)`: 一个用来迭代的集合。
* `[predicate=_.identity] (Array|Function|Object|string)`: 每次迭代调用的函数。

**返回值：**

* `(boolean)`: 如果所有元素经 predicate（断言函数） 检查后都都返回真值，那么就返回true，否则返回 false 。

**例子：**

```javascript
_.every([true, 1, null, 'yes'], Boolean);
// => false

var users = [
  { 'user': 'barney', 'age': 36, 'active': false },
  { 'user': 'fred',   'age': 40, 'active': false }
];

// The `_.matches` iteratee shorthand.
_.every(users, { 'user': 'barney', 'active': false });
// => false

// The `_.matchesProperty` iteratee shorthand.
_.every(users, ['active', false]);
// => true

// The `_.property` iteratee shorthand.
_.every(users, 'active');
// => false
```
