In the text, keep in mind the differences in the browser version of the pits.
Copy Code code as follows:
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 ("Traversal attribute");
for (var i in TMP) {
Alert (Tmp[i]);
}
Alert ("Traversal array");
for (Var i=0;i<tmp.length;i++) {
Alert (Tmp[i]);
}
If you are a IE8 browser, for example (IE7, IE9, Chrome, FF, test only these types)
The result is the same through attribute and array traversal.
But for IE8, the result will be a little bit different, under IE8 will be the prototype chain extension method as a property output, you can test.
This difference is also due to the resolution of a bizarre bug in which a colleague uses for (Var i in TMP) to traverse each element of the array in the code, and this problem occurs if the prototype chain method is exactly defined for the array.
Therefore, it is recommended that you should use the standard notation for (var i=0;i<tmp.length;i++) If you are traversing an array element.