> I can remove objects from an array by doing this:[color=blue]
>
> for (i in oCache){
> if (i == "test"){
> delete oCache[i];
> };
> };
>
> However, the array's length property is unaffected.
>
> If I use splice like so:
>
> for (i in oCache){
> if (i == "test"){
> oCache.splice(i, 1);
> };
> };
>
> It breaks because oCache's length is altered within the loop by splice.
>
> How do I iterate though an array, remove items AND change the length
> property?[/color]
You should not be using an array if the subscripts are not integers.
That is what objects are for.
The array.length property is supposed to be 1 larger than the largest
integer subscript. The array.splice method has no effect on array.test.
If you misuse language features, you can easily get confused.
Perhaps your example is wrong, and you really are dealing with integer
subscripts. (There is a difference between test and "test".) In that
case, loop through backwards.
for (i = oCache.length - 1; i >= 0; i -= 1) {
See
http://www.crockford.com/javascript/survey.html