looks like you are creating a global here? I would use a forEach or save length before the loop.