delete will leave "holes" in the array and will not reduce the length.

I think you should use the array splice() function instead here.