JavaScript Tutorial/Array/toSource

Материал из Web эксперт
Перейти к: навигация, поиск

Array.toSource()

The toSource() method returns one string representing the source of the Array object.

The string contains all the elements in the array separated with commas.

The entire string is enclosed with brackets ([]).

If another array is contained within an array, its contents are also part of the string with its own set of brackets.



<html>
    <script language="JavaScript">
    <!--
    numbers = new Array(3,6,7);
    colors = new Array("Blue","Green","Red",numbers);
    aString = colors.toSource();  
    document.write(aString); 
    -->
    </script>
</html>


Two dimensional array toString

<html>
    <script language="JavaScript">
    <!--
    numbers = new Array(3,6,7);
    colors = new Array("Blue","Green","Red",numbers);
    aString = colors.toSource();  
    document.write(aString); 
    -->
    </script>
</html>