JavaScript array Some () and filter ()

Source: Internet
Author: User

Some method

Array1.some (callbackfn[, Thisarg])

The callback function CALLBACKFN is called for each element in the array array1, and the some method terminates when the callback function returns TRUE or iterates through all the arrays. Optional parameter Thisarg can replace the This object in the callback function

Filter method

Array1.filter (callbackfn[, Thisarg])

The callback function Callbackfn method is called by each element in the array array1, and the method returns a new collection of elements that return true in the callback function. Optional parameter Thisarg can replace the This object in the callback function

The difference between the two

The Some method returns a Boolean value that can be used to inspect an array for an object

The filter method returns a new array that can be used to filter the objects in the array

JavaScript array Some () and filter ()

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.