Skip to content

Instantly share code, notes, and snippets.

@dtomasi
Last active August 31, 2018 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtomasi/609809aaa0c2c003d26b to your computer and use it in GitHub Desktop.
Save dtomasi/609809aaa0c2c003d26b to your computer and use it in GitHub Desktop.
get length on an Object
/**
* Global function for Counting length of an Object
* @copyright tomasiMEDIA 2013
* @author Dominik Tomasi
* @date 09.10.13
*/
(function($,window){
$.fn.objectLength = function(){
var $this = $(this);
return count($this);
};
window.objectLength = function(el){
return count(el);
};
function count(el){
var count = 0;
var i;
for (i in el) {
if (el.hasOwnProperty(i)) {
count++;
}
}
return count;
}
})(jQuery,window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment