Created
August 29, 2013 19:53
-
-
Save syropian/6382640 to your computer and use it in GitHub Desktop.
A few handy JS helper methods for getting the count of a JS object, as well as getting the index of an object by key.
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
//Helper Methods | |
function getObjectCount(obj) { | |
var count = 0; | |
var key; | |
for(key in obj) { | |
if(obj.hasOwnProperty(key)) count++; | |
} | |
return count; | |
} | |
function getIndexOfObjectKey(obj, attr) { | |
var i = 0; | |
$.each(obj, function(k, v){ | |
if(k === attr) return false; | |
i++; | |
}); | |
return i; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment