jquery each and map differences

Source: Internet
Author: User
Jquery.each (object, [callback])

A general-purpose example of a method that can be used to sample objects and arrays.

Unlike the $ (). each () method of the JQuery object, this method can be used to sample any object. The callback function has two parameters: the first is the index of the object's member or array, and the second is the corresponding variable or content. If you need to exit each loop so that the callback function returns false, the other return values are ignored.

Jquery.map (Arr|obj,callback)

Converts an element in an array to another array.

The conversion function as a parameter is called for each array element, and the conversion function is passed a parameter that represents the transformed element. The conversion function can return a converted value, null (delete an item in an array), or an array containing a value, and extend to the original array.

---------------------------------------------------------------------------------------------------------

The use of each function and the map function in jquery looks similar, but there is a little bit of a difference.

Each returns an array of the original, and does not create a new one.

The map method returns a new array.

jquery each and map differences

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.