Create comma-delimited string

前端 未结 5 783
不思量自难忘°
不思量自难忘° 2021-01-01 09:06

I\'m looking to find a neat way to create a comma-delimited string from an array. This is how I\'m doing it now...

for(i=0;i<10;i++)
{
   str = str + \',\         


        
相关标签:
5条回答
  • 2021-01-01 09:34

    I think there is something like array.join(',') where array is your array variable instance.

    0 讨论(0)
  • 2021-01-01 09:38

    you have to use

    var joinedstr = myarray.join(',');

    0 讨论(0)
  • 2021-01-01 09:44

    Array.prototype.join() is what you're looking for:

    arr.join(',');
    

    https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/join


    var arr = ['Hi', 'I', 'am', 'a', 'comma', 'separated', 'list'];
    
    arr.join(',');  // === "Hi,I,am,a,comma,separated,list" 
    
    0 讨论(0)
  • 2021-01-01 09:46

    Use the join method:

    arr.join(',');
    
    0 讨论(0)
  • 2021-01-01 09:58

    Use the join function:

    myarray.join(',');

    0 讨论(0)
提交回复
热议问题