Last active
August 29, 2015 14:06
-
-
Save tracend/71e3cb5069edaa0bceae to your computer and use it in GitHub Desktop.
Handlebars.size: get the size of an object #handlebars #helper #cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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