Implode an array with JavaScript?

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

Can I implode an array in jQuery like in PHP?

7条回答
  •  深忆病人
    2021-01-29 22:39

    For future reference, if you want to mimic the behaviour of PHP's implode() when no delimiter is specified (literally just join the pieces together), you need to pass an empty string into Javascript's join() otherwise it defaults to using commas as delimiters:

    var bits = ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd'];
    alert(bits.join());    // H,e,l,l,o, ,W,o,r,l,d
    alert(bits.join(''));  // Hello World
    

提交回复
热议问题