How to echo array in Javascript

You can echo javascript array value as comma separated string in javascript.

Answers 2
  • Display javascript array value as comma seprated string using toString() method

    <script> 
    const seasons = ['spring', 'summer','autumn', 'winter'];
    let text = seasons.toString();
    console.log(text); 
    </script>
    
    0

    Output:

    spring,summer,autumn,winter

    You can use toString() method to display array javascript value as comma seprated string in javascript.

  • Display an array element by specifying the index to array in javascript

    <script> 
    const seasons = ['spring', 'summer','autumn', 'winter'];
    let season = seasons[0];
    console.log(season);
    </script>
    
    0

    Output:

    spring

    You can display an array element by specifying the array index to array in javascript. You have to pass the array index (strat with 0) which you want to get from the array.

  • Back to code snippet queries related javascript