Iterate JS arrays with a C-style for loop, not for-in

for-in is not guaranteed to walk the arrays in order (although it often
does on most browsers).  Preserving order is important since we're
cloning and appending elements into another select.
Use local variable declarations instead of polluting global space