Skip to content

Instantly share code, notes, and snippets.

@bjrnqprs
Created July 20, 2013 14:22
Show Gist options
  • Save bjrnqprs/6045211 to your computer and use it in GitHub Desktop.
Save bjrnqprs/6045211 to your computer and use it in GitHub Desktop.
jQuery function to retrieve the size of an object.
jQuery.extend({
getObjectLength: function(obj){
var length = 0;
if(typeof obj == 'object') {
if(Object.keys) {
length = Object.keys(obj).length;
} else {
var i;
for(i in obj) {
if(obj.hasOwnProperty(i)) {
length++;
}
}
}
return length;
}
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment