How to convert array to string with toString()

Description

The toString() and valueOf() methods return the same value when called on an array.

Example


var colors = ["red", "blue", "green"]; 
    /* w  ww .j a v a2 s .c  o  m*/
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.





















Home »
  Javascript »
    Javascript Reference »




Array
Canvas Context
CSSStyleDeclaration
CSSStyleSheet
Date
Document
Event
Global
History
HTMLElement
Input Element
Location
Math
Number
String
Window