arr.toString() returns the string representation of the array elements. The syntax of this function is as follows:
arr.toString()
Arguments
This function does not take any arguments.
Return value
The function returns the string representation of the array elements. If the array is empty, then it returns an empty string.
Example for the above function is provided below:
Example 1:
var arr = [2, 5, 8, 1, 4] print(arr.toString());
Output:
2,5,8,1,4
In this example the function toString() creates a string consisting of array elements.
Code for the above function is provided below:
Program 1:
<script> // JavaScript to illustrate toString() function function func() { // Original array var arr = [2, 5, 8, 1, 4]; // Creating a string var str = arr.toString(); document.write(str); } func(); </script> |
Output:
2,5,8,1,4
leave a comment
0 Comments