Because converting an array to a string will call .toString which is basically the same as calling .join(), which will call .toString onto all elements in the array, and then delemit the result with a comma. Therefore the arrays get recursively joined to a string, the result looks flattened as there is no indicator for the start or end of the array.
Here is the conversion step by step:
[[1, 2, 3], [1, 2, 3]].toString()
[1, 2, 3].toString() + "," + [1, 2, 3].toString()
(1 + "," + 2 + "," + 3) + "," + (1 + "," + 2 + "," + 3)
"1,2,3" + "1,2,3"
"1,2,3,1,2,3"
['a','b','c','d','e','f']or the desired result"abcdef"alert(String(['a', 'b', ['c', 'd', ['e', {erm:'notsogood'}]]]));Not a good way. Are you assuming all arrays are going to be characters?