Restores use of forEach iterating on non-array values. Fixes #345

Both loops need to check if i exists to avoid sparse array holes