[removed] nice human readable join of list

前端 未结 7 1675
半阙折子戏
半阙折子戏 2021-01-26 10:11

Having a list (array) of tags [\'tag1\', \'tag2\', \'tag3\'] I want to generate a nice title like: Content tagged tag1, tag2 and tag3.

For the

相关标签:
7条回答
  • 2021-01-26 10:29

    Try like this

    var g = ['tag1', 'tag2', 'tag3'];
    var title = g.slice(0, g.length-1).join(',').concat(' and ').concat(g[g.length-1]);
    
    0 讨论(0)
提交回复
热议问题