How to convert array to string with valueOf()
Description
The toString()
and
valueOf()
methods return the same value when called on an array.
Example
var colors = ["red", "blue", "green"];
/*from w ww. j a va 2 s .com*/
console.log(colors.toString()); //red,blue,green
console.log(colors.valueOf()); //red,blue,green
console.log(colors); //red,blue,green
The code above generates the following result.
Example 2
The following code shows how to use array.valueOf with a two dimensional array.
var numbers = new Array(3,6,7);
var colors = new Array("Blue","Green","Red",numbers);
console.log(colors.valueOf());
The code above generates the following result.