Get rid of O(n^2) string-concat.

See e.g. http://stackoverflow.com/questions/2781686/javascript-string-concatenation-slow-performance-array-join