JS 复制字符的方法

repeat

  • 复制字符串
const abc = 'abc'
abc.repeat(2) // abcabc

padStart

  • 复制字符串,如果长度小于制定的长度,在开始位置填充字符,直到满足长度条件。
const abc = 'abc'
abc.padStart(5,'.') // ..abc

padEnd

  • 复制字符串,如果长度小于制定的长度,在字符串结束位置填充字符,直到满足长度条件。
const abc = 'abc'
abc.repeat(5,'.') // abc..
posted @ 2022-07-10 11:45  DL·Coder  阅读(1374)  评论(0)    收藏  举报