Skip to content

Instantly share code, notes, and snippets.

@tracend

tracend/handlebars.size.js

Last active Aug 29, 2015
Embed
What would you like to do?
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