Skip to content

Instantly share code, notes, and snippets.

@badsyntax
Created July 19, 2010 09:49
Show Gist options
  • Save badsyntax/481216 to your computer and use it in GitHub Desktop.
Save badsyntax/481216 to your computer and use it in GitHub Desktop.
// usage: var size = $.size( selectorOrObject );
// code borrowed from: http://stackoverflow.com/questions/5223/length-of-javascript-associative-array
$.size = function(obj){
if ( typeof obj === 'object' ) {
var size = 0, key;
for (key in obj) {
if ( obj.hasOwnProperty( key ) ) {
size++;
}
}
return size;
} else {
return $( obj ).size();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment