Skip to content

Instantly share code, notes, and snippets.

@till
Created August 28, 2010 15:53
Show Gist options
  • Select an option

  • Save till/555278 to your computer and use it in GitHub Desktop.

Select an option

Save till/555278 to your computer and use it in GitHub Desktop.
/*
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]);
}
@till

till commented Aug 28, 2010

Copy link
Copy Markdown
Author

Fix:

for (var x = 0; x < testArray.length; x++) { }

@janl

janl commented Aug 28, 2010

Copy link
Copy Markdown

testArray.forEach(function(element) {
sys.puts(element);
});

@andrerom

Copy link
Copy Markdown

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