Iterate through elements in array instead of object fields.

This is a fix for #2338.