[removed] nice human readable join of list

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

    From my view, This is an simple approach

    var tags = ['tag1', 'tag2', 'tag3'];
    
    console.log("Content tagged " + tags.slice(0, -1).join(', ')+' and '+tags.slice(-1));
    

    Hope it helps you :) JsFiddle

提交回复
热议问题