refactored the loop for rendering arrays

I refactored the loop which is responsible for building the HTML string for arrays.
I did this for two reasons:
* performance (iterate only once over the array)
* Accordance with the ECMA standard: the standard does not specify the order in which a `for(...in...)` loop returns the contents of an array (http://www.ecma-international.org/ecma-262/5.1/#sec-12.6.4).