Quite (I suppose) simple function counting dimensions BOTH in Arrays and array-like Objects (like in your case):
function countDimensions(arr)
{
if (! (arr && typeof arr === 'object') ) {
return 0;
}
var maxCount = Math.max.apply(null, $.map(arr, function(n) {
return countDimensions(n);
}));
return 1 + (isFinite(maxCount) ? maxCount : 0);
}
jQuery is used, as 0) it's mentioned in tags, 1) naive checking for Array with instanceof Array can lead to tricky results in multiframe apps, 2) $.map is a convenient shortcut for moving through all the array values.
It can be rewritten in plain JS, of course, but it won't be as compact. )
Had to use isFinite check, as protomax-ing an empty array gives -Infinite.