Files
freeCodeCamp/guide/chinese/javascript/es6/some-function/index.md
2018-10-16 21:32:40 +05:30

25 lines
770 B
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Some Function
localeTitle: 一些功能
---
## 一些功能
`some()`函数用于验证数组中是否至少有一个元素满足给定条件。如果条件由一个元素满足,则该函数返回`true`如果任何元素满足条件则返回false
某些函数的原始语法是:
```javascript
arr.some(function callback(currentValue, index, array) {
// Do some stuff with currentValue (index and array are optionals)
}, [thisArg]);
```
### 示例ES6
```javascript
const arr = [1, 4, 5, 11];
if (arr.some(el => el % 2 == 0)) {
console.log("There's at least one even number");
}
```
`some()``Array`对象的一个方法因此要将该函数传递给一个可迭代对象必须确保该对象是一个Array。