Skip to content

Instantly share code, notes, and snippets.

@emphaticsunshine
Created August 13, 2012 23:33
Show Gist options
  • Select an option

  • Save emphaticsunshine/3344831 to your computer and use it in GitHub Desktop.

Select an option

Save emphaticsunshine/3344831 to your computer and use it in GitHub Desktop.
Object caching
var employees = [
{
"firstName": "John",
"lastName": "Doe"
},
{
"firstName": "Anna",
"lastName": "Smith"
},
{
"firstName": "Peter",
"lastName": "Jones"
}
];
/*This is not a preferred way*/
for (var x in employees){
console.log( employees[x].firstName, employees[x].lastName);
}
/*This is a preferred way */
var currentEmployee;
for ( var x in employees ){
currentEmployee = employees[x];
console.log( currentEmployee.firstName, currentEmployee.lastName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment