We now use the toString() method to read the value of the array.

The toString() method in an array converts each element to a string, which is then displayed as a comma concatenated output.

var str = [1.2.3.4.5.6.7.8.9.0]; // Define an array
var s = str.toString();  // Convert an array to a string
console.log(typeof s);  // Returns the string string, indicating that it is a string
Copy the code

Casts.

// cast to String with ""+
var str = ""+ 1234;
console.log(typeof str);
// cast to Boolean with!!
var bool = !!"c";
console.log(typeof bool); // boolean
// Cast to Number with +
var num = +"1234";
console.log(typeof num); // number
Copy the code

When an array is used in a string environment, JavaScript automatically calls the toString() method to convert the array to a string. In some cases, you need to call this method explicitly.