How to use JavaScript Array toString()

Program to use JavaScript Array toString() method


let a = [1, 2, 'Apple', '3', '7', 'Banana'];
let b = a.toString();


console.log(b);

Output


1,2,Apple,3,7,Banana

Steps Description

  1. Declare two variable a and b
  2. Initialize two variable with value of array a = [1, 2, 'Apple', '3', '7', 'Banana'] and b = a.toString()
  3. Array toString() method converts the array to a string.
  4. The value of b variable is displayed with the help of console.log inbuilt function