Home>Article>Web Front-end> What is the role of some in es6

What is the role of some in es6

WBOY
WBOY Original
2022-04-08 18:11:07 4971browse

In es6, the function of some is to detect whether there is an element with specified conditions in the array; if the specified element exists, the returned result is true, if the specified element does not exist, the returned result is false, syntax is "array.some(callback function),thisValue)".

What is the role of some in es6

The operating environment of this article: Windows 10 system, ECMAScript version 6.0, DELL G3 computer.

What is the role of some in es6

The some() method tests whether an element in the array passes the test implemented by the provided function.

Syntax

array.some(callback[, thisObject]);

Parameter details

callback - Function that tests each element.

thisObject - The object to use when executing the callback.

Return value

If an element passes the test, it returns true, otherwise it returns false.

Example

function isBigEnough(element, index, array) { return (element >= 10); } var retval = [2, 5, 8, 1, 4].some(isBigEnough); console.log("Returned value is : " + retval ); var retval = [12, 5, 8, 1, 4].some(isBigEnough); console.log("Returned value is : " + retval );

Output

What is the role of some in es6

[Related recommendation: "vue.js tutorial"]

The above is the detailed content of What is the role of some in es6. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn