IE8 uses the property Traversal method for JS arrays to parse different points:

Source: Internet
Author: User

Print? Array. prototype. Contains = function (str ){
If (! Str) return false;
For (var I = 0;
I <this. length; I ++ ){
If (this [I] = str) {return true ;}}
Return false ;}
Var tmp = new Array ();
Tmp. push ("1 ");
Tmp. push ("2 ");
Tmp. push ("3"); alert ("traverse attributes ");
For (var I in tmp ){
Alert (tmp [I]);} alert ("traversing array ");
For (var I = 0; I <tmp. length; I ++ ){
Alert (tmp [I]);} Array. prototype. Contains = function (str ){
If (! Str)
Return false;
For (var I = 0; I <this. length; I ++ ){
If (this [I] = str ){
Return true;
}
}
Return false;
}

Var tmp = new Array ();
Tmp. push ("1 ");
Tmp. push ("2 ");
Tmp. push ("3 ");
Alert ("traversing attributes ");
For (var I in tmp ){
Alert (tmp [I]);
}
Alert ("traversing arrays ");
For (var I = 0; I <tmp. length; I ++ ){
Alert (tmp [I]);
} For non-IE8 browsers, such as IE7, IE9, Chrome, and FF, only test these browsers)
The result is the same for retrieving attributes and arrays.

However, for IE8, there will be a slight difference in the results. In IE8, the prototype chain extension method will be used as an attribute output. You can test it.

This difference was also found because it solved a strange bug. Some colleagues used for (var I in tmp) in the code to traverse every element of the array, if the prototype chain method is defined for Array, this problem occurs.

Therefore, we recommend that you use the standard syntax for (var I = 0; I <tmp. length; I ++) to traverse array 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.