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