Use for statement instead of Array.prototype.forEach

forEach doesn't apply modified array's length