<分区>
有什么简单的方法可以在 jQuery/JS 中乘以字母数字字符串吗?
例如
var str = "ABC";
console.log( str * 5 ); // this will nerutn `Nan`
// where what i want is `ABCABCABCABCABC`
非常感谢任何建议。
标签 javascript jquery
<分区>
有什么简单的方法可以在 jQuery/JS 中乘以字母数字字符串吗?
例如
var str = "ABC";
console.log( str * 5 ); // this will nerutn `Nan`
// where what i want is `ABCABCABCABCABC`
非常感谢任何建议。
最佳答案
我在这里看到确切的问题:
只需将此添加到您的代码中:
String.prototype.repeat = function( num )
{
return new Array( num + 1 ).join( this );
}
var str = "ABC";
console.log( str.repeat(5) ); // this will return `ABCABCABCABCABC`
关于javascript - jQuery - 乘以字母数字字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7647812/