Skip to content

Instantly share code, notes, and snippets.

@danbrianwhite
Created April 15, 2013 01:45
Show Gist options
  • Save danbrianwhite/fc0cf6d3e1d117cca4e2 to your computer and use it in GitHub Desktop.
Save danbrianwhite/fc0cf6d3e1d117cca4e2 to your computer and use it in GitHub Desktop.
get number of items in object or array
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