for-loop fix removes 'undefined' from reset dialog. See #12301 (rebased onto dev_5_0)

This is the same as gh-2560 but rebased onto dev_5_0.

Although this is not yet merged into develop, I have rebased it here before code-freeze to get it merged into dev_5_0 first.

----

Fixes https://trac.openmicroscopy.org.uk/ome/ticket/12301

To test:
 - open full image viewer, click "Edit" channels then "Reset".
 - Dialog should only have 2 buttons: OK & Cancel.
 - Also confirm that plates are still displayed correctly (no change in labels/layout).
 - Also check that color-picker in main image viewer still works (shows 10 preset colours to pick)
                    
To continue the discussion from gh-2560: The original bug has been fixed and I've also fixed other usages of ``` for ... in ``` that could potentially cause bugs.