背景
重复一个字符串多次的方法有哪些?
String.prototype.repeat
输出是'bbbbbbbbbb',因为我们指定要重复'b' 10 次
const str = "b".repeat(10);
console.log(str);
Array Constructor
const str = Array(11).join("b")
console.log(str);
Use a Loop
let word = ''
for (let times = 0; times < 10; times++) {
word += 'b'
}
console.log(word)
Lodash repeat Method
const word = _.repeat('b', 10)
console.log(word)