Created
April 15, 2013 01:45
-
-
Save danbrianwhite/fc0cf6d3e1d117cca4e2 to your computer and use it in GitHub Desktop.
get number of items in object or array
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
function getNumberItemsObject(arrays) | |
{ | |
var itemsLeft; | |
for (property in arrays) | |
{ | |
if (typeof(itemsLeft) === "undefined") | |
{ | |
itemsLeft = arrays[property].length; | |
} | |
else if (itemsLeft > arrays[property].length) | |
{ | |
itemsLeft = arrays[property].length; | |
} | |
} | |
return itemsLeft; | |
} | |
function getNumberItemsArray(arrays) | |
{ | |
var itemsLeft; | |
for (var i = arrays.length - 1; i >= 0; i--) | |
{ | |
if (typeof(itemsLeft) === "undefined") | |
{ | |
itemsLeft = arrays[i].length; | |
} | |
else if (itemsLeft > arrays[i].length) | |
{ | |
itemsLeft = arrays[i].length; | |
} | |
}; | |
return itemsLeft; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment