Skip to content

Instantly share code, notes, and snippets.

@tracend
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tracend/71e3cb5069edaa0bceae to your computer and use it in GitHub Desktop.
Save tracend/71e3cb5069edaa0bceae to your computer and use it in GitHub Desktop.
Handlebars.size: get the size of an object #handlebars #helper #cc
// Handlebars.size: get the size of an object
// Source: https://gist.github.com/tracend/71e3cb5069edaa0bceae
Handlebars.registerHelper('size', function(obj) {
// prerequisite
if( typeof obj != "object" ) return;
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment