[removed] nice human readable join of list

前端 未结 7 1685
半阙折子戏
半阙折子戏 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:20

    Try this,

    var arr = ['tag1', 'tag2', 'tag3']; 
    var lastStr = arr.pop();
    var str = "Content tagged " + arr.join(", ") + " and " + lastStr;
    

提交回复
热议问题