Implode an array with JavaScript?

后端 未结 7 2099
醉话见心
醉话见心 2021-01-29 22:14

Can I implode an array in jQuery like in PHP?

相关标签:
7条回答
  • 2021-01-29 22:52

    We can create alternative of implode of in javascript:

    function my_implode_js(separator,array){
           var temp = '';
           for(var i=0;i<array.length;i++){
               temp +=  array[i] 
               if(i!=array.length-1){
                    temp += separator  ; 
               }
           }//end of the for loop
    
           return temp;
    }//end of the function
    
    var array = new Array("One", "Two", "Three");
    
    
    var str = my_implode_js('-',array);
    alert(str);
    
    0 讨论(0)
提交回复
热议问题