JavaScript some () function usage detailed, javascriptsome_php tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.