Array.toSource() (Method)

Output an array formatted as an Array literal contained in a string.


JavaScript - 1.3
JScript - 3.0
Internet Explorer - 4.0
Netscape - 4.06
Property/method value type:String primitive
JavaScript syntax:-myArray.toString()

This is an alternative way to deliver a string version of an array. In this case, it is formatted as an Array literal and can then be used in an eval() function to assign another array. It means that Arrays can be deep copied more easily.

This functionality was previously available in Netscape 4 when the toString() method was executed in a <SCRIPT> block that was evaluated under explicit JavaScript version 1.2 language selection.

If you run the example, it should yield something like this:

["one", 2, "III"]

This is quite different to the result of a toString() method which would yield this for the same array contents:


The result of this method is a String primitive version of the array formatted as an Array literal.

Example code:

   // Create an array and display its source
   myObject = new Array("one", 2, "III");

See also:Array.prototype, Array.toString()