Home > Backend Development > PHP Tutorial > Detailed explanation of the usage of javascript some() function, javascriptsome_PHP tutorial

Detailed explanation of the usage of javascript some() function, javascriptsome_PHP tutorial

WBOY
Release: 2016-07-13 10:14:16
Original
1593 people have browsed it

Detailed explanation of the usage of javascript some() function, javascriptsome

Parameter Description
callback: The callback function to be executed for each array element.
thisObject: this object defined when executing the callback function.

Function Description
Execute the specified function (callback) once for each element in the array until this function returns true. If this element is found, some will return true. If the callback function returns false after executing each element, some will return false. . It only performs the specified function on non-empty elements in the array. Elements that have no value assigned or have been deleted will be ignored.

The callback function can have three parameters: the current element, the index of the current element and the current array object.

If the parameter thisObject is passed in, it will be used as the this object inside the callback function (callback). If it is not passed or is null, the global object will be used.

Copy code The code is as follows:



some will not change the original array. Remember: only the array elements passed in before the callback function is executed are valid. Elements added after the callback function starts to execute will be ignored, and the elements added after the callback function starts to execute will be ignored until the end. During this period, if an array element is deleted or changed, it will be based on the time when the callback function accesses the element, and the deleted element will be ignored.

Check if all array elements are greater than or equal to 10

Copy code The code is as follows:

function isBigEnough(element, index, array) {
return (element >= 10);
}
var passed = [2, 5, 8, 1, 4].some(isBigEnough);
// passed is false
passed = [12, 5, 8, 1, 4].some(isBigEnough);
// passed is true

Do you guys know something about the some() function? If you have any questions, you can leave me a message

http://www.bkjia.com/PHPjc/910589.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/910589.htmlTechArticleDetailed explanation of the usage of javascript some() function, javascriptsome parameter description callback: The callback function to be executed for each array element. thisObject: This pair defined when executing the callback function...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template