Stop Using for…in Loop Statement to Iterate Array In JavaScript

for…in loop statement is working fine. The problem is it does not work with Prototype. So standard loop statement is encouraged:

; for (var index=0; index { ; var item = myArray[index]
// Your code working on item here...
}

In addition, if the array is so large, each time to check the length will be so costly. Use following statement instead:

; for (var index=0, len=myArray.length; index { ; var item = myArray[index]
// Your code working on item here...
}


http://www.prototypejs.org/api/array

No comments:

Post a Comment

Labels