js字符串重复 repeat() - Kaiqisan

js字符串重复 repeat()

把这个方法单独拎出来就是因为没有什么方法还有比它更加特殊了。

str.repeat(n)重复字符串n遍,括号内填重复的遍数

const laugh = "我笑得满地找头"
const sentence = `${
      
      "哈".repeat(8)},${
      
      laugh},${
      
      "哈".repeat(7)}`
console.log(sentence)
//输出为 哈哈哈哈哈哈哈哈,我笑得满地找头,哈哈哈哈哈哈哈

emm找不到什么这个方法的正经的用途,大家看情况使用吧。

猜你喜欢

转载自blog.csdn.net/qq_33933205/article/details/108006989
今日推荐