JQuery traverses each and map function instances

Source: Internet
Author: User
This article introduces the very useful traversal functions each and map functions in jQuery, and compares the usage methods of these two functions. I believe this is very helpful to everyone, for more information about the coders, see. Each usage

1. each in the array

Var arr = ["one", "two", "three", "four"]; $. each (arr, function () {alert (this) ;}); // The above each Outputs one, two, three, four var arr1 = [[1, 4, 3], [4, 6, 6], [7, 20, 9] $. each (arr1, function (I, item) {alert (item [0]) ;}); // In fact, arr1 is a two-dimensional array, and item is equivalent to taking every one-dimensional array, // item [0] is relative to the first value in each one-dimensional array. // The above each output is: 1 4 7 var obj = {one: 1, two: 2, three: 3, four: 4}; $. each (obj, function (I) {alert (obj [I]) ;}); // This each is more powerful and can loop through every attribute. // The output result is: 1 2 3 4

2. Traverse Dom elements

Related Article

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.