The elements in the array are converted to strings and are concatenated together to form a larger string.
This is functionally identical to using the join() method with no join string argument.
If you run the example, it will yield the following:
one,2,III
This is quite different to what you get if you use the toSource() method which presents this result:
["one", 2, "III"]
The result of this method is a String primitive version of the array assembled by concatenation.
Netscape supports a special conversion mechanism if this method is invoked within a <SCRIPT> HTML tag whose LANGUAGE attribute is set to the "JavaScript1.2" value.
In that circumstance, the array is presented with enclosing square brackets. This means that it can be used as an array literal in an eval() function. This behavior was added in anticipation of the ECMA specification supporting some additional functionality. However, the standard mandates very specific behavior for toString().
In JavaScript 1.3, the toString() behavior will revert to what was expected. Because this source form output is so useful, it will continue to be supported by a new method called toSource().
// Create an array and display it as a string myObject = new Array("one", 2, "III"); document.write(myObject.toString());
Prev | Home | Next |
Array.toSource() | Up | Array.unshift() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |