Skip to content

Instantly share code, notes, and snippets.

@RimonEkjon
Forked from jamesarosen/iteration.js
Last active August 29, 2015 14:05
Show Gist options
  • Save RimonEkjon/dbcd75071ccbaa8a736a to your computer and use it in GitHub Desktop.
Save RimonEkjon/dbcd75071ccbaa8a736a to your computer and use it in GitHub Desktop.
// Array Iteration:
myArray = [ 'foo' ];
myArray.forEach(function(x) { console.log(x); });
// prints "foo"
// Object Keys:
myObject = { foo: 'bar', baz: 'quux' };
Object.keys(myObject); // [ "foo", "baz" ]
// Object Iteration Helper (context is optional)
function objectIteration(obj, fn, context) {
Object.keys(obj).forEach(function(key) {
fn.call(context, key, obj[key]);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment