javascript - jQuery - 乘以字母数字字符串

标签 javascript jquery

<分区>

有什么简单的方法可以在 jQuery/JS 中乘以字母数字字符串吗?

例如

var str = "ABC";
console.log( str * 5 ); // this will nerutn `Nan`
// where what i want is `ABCABCABCABCABC`

非常感谢任何建议。

最佳答案

我在这里看到确切的问题:

Repeat String - Javascript

只需将此添加到您的代码中:

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/

相关文章:

javascript - C# - MVC - JSON - 使用 ViewBag 将列表从服务器端返回到客户端

javascript - Highcharts : area range and spline in the same graph issue

jQuery ajax XML Http 请求不起作用

android - 支持不同尺寸的手机间隙中的多分辨率图像

javascript - 网页之间的数据交易

c# - 无法在动态生成的 div 中显示 Google map

javascript - 按类触发下一个元素的函数

javascript - 连接两个字符串时 += 的作用是什么? ( Eloquent JS FizzBu​​zz)

javascript - 使用输入中的文本添加多种样式的 div

jquery - (jQuery) 如何抓取两个 div 并将它们插入到新的 div 上