How to use JavaScript Array toString()

Array toString

Array toString() method

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

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