The array is not big (max 20 items, generic case is 1 or 2), so I think it's ok here.

If we want to traverse only once we can pass a callback instead (that was my first comment that I deleted, because I think it's not worth the complexity here)