Created
August 28, 2010 15:53
-
-
Save till/555278 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
save the following file as 'array.js' and run with: node array.js | |
*/ | |
sys = require('sys'); | |
Array.prototype.foo = function () { return 'foo'; } | |
Array.prototype.bar = function () { return 'bar'; } | |
var testArray = [1, 2, 3, 4, 5]; | |
for (var x in testArray) { | |
sys.puts(testArray[x]); | |
} |
Fix:
for (var x = 0; x < testArray.length; x++) { }
testArray.forEach(function(element) {
sys.puts(element);
});
for (var x = 0; x < testArray.length; x++) { }
for (var x = 0, l = testArray.length; x < l; x++) { };
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for (var x in testArray) {
if(testArray.hasOwnProperty(x)) {
sys.puts(testArray[x]);
}
}