more resilient loop, works even if array.prototype ahs extra members