Is it fine to display the output of Array.toString()
to the user, or is there a possibility that the string format could change in future versions of ActionScript 3 or other compilers?

- 13,904
- 10
- 69
- 101
3 Answers
Here's an excerpt describing Array.toString from ECMA-262, which ActionScript 3 follows very closely:
15.4.4.2
Array.prototype.toString ( ) When the toString method is called, the following steps are taken:
1. Let array be the result of calling ToObject on the this value.
2. Let func be the result of calling the [[Get]] internal method of array with argument "join".
3. If IsCallable(func) is false, then let func be the standard built-in method Object.prototype.toString (15.2.4.2).
4. Return the result of calling the [[Call]] internal method of func providing array as the this value and an empty arguments list.
And Array.join:
15.4.4.5
Array.prototype.join (separator) The elements of the array are converted to Strings, and these Strings are then concatenated, separated by occurrences of the separator. If no separator is provided, a single comma is used as the separator. The join method takes one argument, separator, and performs the following steps:
1. Let O be the result of calling ToObject passing the this value as the argument.
2. Let lenVal be the result of calling the [[Get]] internal method of O with argument "length".
3. Let len be ToUint32(lenVal).
4. If separator is undefined, let separator be the single-character String ",".
5. Let sep be ToString(separator).
6. If len is zero, return the empty String.
7. Let element0 be the result of calling the [[Get]] internal method of O with argument "0".
8. If element0 is undefined or null, let R be the empty String; otherwise, Let R be ToString(element0).
9. Let k be 1.
10. Repeat, while k < len
a. Let S be the String value produced by concatenating R and sep.
b. Let element be the result of calling the [[Get]] internal method of O with argument ToString(k).
c. If element is undefined or null, Let next be the empty String; otherwise, let next be ToString(element).
d. Let R be a String value produced by concatenating S and next.
e. Increase k by 1.
11. Return R.
So, the default behavior is very well defined, and won't change.

- 4,506
- 22
- 34
It is safe to use it as it is. Array.toString()
has been the same since AS3 came out.

- 79,954
- 26
- 128
- 166

- 15,300
- 3
- 58
- 80
-
That means that it would have been safe to use at least until now :) Is there a language standard or a statement from Adobe to this effect? – Tim Jul 13 '11 at 16:25
-
1Yeah so in AS3 it has never changed and it never will. There is no official statement or any guarantees, but `Array.toString()` will definitely be one of the least likely of any method in the language to change. – citizen conn Jul 13 '11 at 16:41
-
Agreed, it's highly unlikely that Adobe would change the behavior of such an established API. However, it is possible for your program to do this by extending Array and overriding toString(), or even setting another implementation on the Array prototype object (Javascript style) -- although of course, you would know if this were the case. – Peter Jul 13 '11 at 17:45
Return value of Array.toString()
is by now equal to that of Array.join()
.
If you are that concerned about this behaviour not changing, use Array.join()
(or, to be completely pedantic, Array.join(',')
) explicitly, and you'll be safe. Joining array works this way since ActionScript exists and it's absolutely unlikely that Adobe will change something to it and loose backwards compatibility (and, well, sanity).

- 3,522
- 17
- 32