Skip to content

Instantly share code, notes, and snippets.

@jamesarosen
Created August 28, 2012 22:43
Show Gist options
  • Save jamesarosen/3505021 to your computer and use it in GitHub Desktop.
Save jamesarosen/3505021 to your computer and use it in GitHub Desktop.
JavaScript fundamentals
// 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