When you work with asynchronous AJAX callbacks, you might need to store the
callback results in an array to process them later. The tricky part is to keep the array size at minimum. In order to do this, you can empty the array item when you are
done with processing it and make it available for future callback results and always
insert the new callback result to the first available array item.



function InsertActiveCallbackArr(arrayObj, arrayElem)
{
var i = 0;
for (var loopCnt = arrayObj.length; (i < loopCnt) && arrayObj[i];i++);
arrayObj[i] = arrayElem;
}

When you are done with the callback result, simply set that array item to null.



function ProcessActiveCallbackArr(arrayObj)
{
for (var i = 0, loopCnt = arrayObj.length; i < loopCnt; i++)
{
// Process the callback result here
// Then set the array item to null
arrayObj[i] = null;
}
}