JavaScript some () function usage in detail, javascriptsome
Parameter description
Callback: The callback function to execute for each array element.
Thisobject: The This object that is defined when the callback function is executed.
Function description
Each element in an array executes one specified function (callback) at a time until this function returns True, and if this element is found, some returns true if the callback function returns false after each element is executed, some will return false. It executes the specified function only for non-empty elements in the array, no assignment, or the deleted element is 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 treated as the this object inside the callback function (callback), and if it is not passed or null, the global object will be used.
Copy the Code code as follows:
Some does not change the original array, remember that only the array elements passed in before the callback function executes, the elements that are added after the callback function begins execution are ignored, and the elements of the array are deleted or changed when the callback function begins execution to the last element. When the callback function accesses the element, the deleted element is ignored.
Checks if all array elements are greater than or equal to 10
Copy the Code code as follows:
function Isbigenough (element, index, array) {
Return (element >= 10);
}
var passed = [2, 5, 8, 1, 4].some (Isbigenough);
Passed is false
Passed = [5, 8, 1, 4].some (Isbigenough);
Passed is true
Did the little friends know anything about the some () function, or would you like to leave a message for me?
http://www.bkjia.com/PHPjc/910589.html www.bkjia.com true http://www.bkjia.com/PHPjc/910589.html techarticle The JavaScript some () function is used in detail, javascriptsome parameter description callback: The callback function to execute on each array element. Thisobject: The This pair defined when the callback function is executed ...