How to convert array into string without comma and separated by space in javascript without concatenation?

后端 未结 4 1283
余生分开走
余生分开走 2020-12-03 06:53

I know you can do this through looping through elements of array and concatenating. But I\'m looking for one-liner solutions. toString() and join() returns string with eleme

4条回答
  •  广开言路
    2020-12-03 07:11

    When you call join without any argument being passed, ,(comma) is taken as default and toString internally calls join without any argument being passed.

    So, pass your own separator.

    var str = array.join(' '); //'apple tree'
    // separator ---------^
    

    MDN on Array.join

提交回复
热议问题