If the array value at the current index is empty, the callback will be called with undefined as value.
The number of iterations is limited to the initial array size, but we still need to check if the array did shrink since then before accessing each element. Fixes #1992.