For loop with for in,$ ('). The difference between each and $.each

Source: Internet
Author: User

One: The difference between a for loop and for

The for...in statement is used to loop an array or an object's properties.

Grammar:

For (variable in object)
{
Execute code here
}

A For loop is a loop of elements of an array, and cannot be cited for non-object arrays (class array objects can also traverse).

Grammar:

for (int variable initial value; condition; increment or decrement) {
Execute code here
}

Iterates through the properties of the Window object with for.

 for (var in window) {    console.log (Winodw[prop])}

Iterates over the array elements with a for inb.
 for (var in array) {    console.log (Array[ele]);}
Implemented with a For loop
 for (var i=0;i<array.length;i++) {    alert (array[i]); // elements of an array }
the best tool for detecting types is: typeof  Two: $ ('). The difference between each and $.each$ (").

Each () method specifies the function to run for each matching element.

Tip: Return False to Stop the loop early.

$ (selector). each (function (index,element))
    • Index-the index position of the selector
    • Element-current elements (can also use the "this" selector)
 $.each
iterates over the property values of an object, an array, and processes it.
var arr1 = ["AAA", "BBB", "CCC" ];         function (i,val) {            alert (i);         Alert (val);  });  

 

For loop with for in,$ ('). The difference between each and $.each

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.