Is there any simple way to multiply alphanumeric string in jQuery / JS?
e.g
var str = "ABC";
console.log( str * 5 ); // this will nerutn `Nan`
// where what i want is `ABCABCABCABCABC`
Any suggestion much appreciated.
Is there any simple way to multiply alphanumeric string in jQuery / JS?
e.g
var str = "ABC";
console.log( str * 5 ); // this will nerutn `Nan`
// where what i want is `ABCABCABCABCABC`
Any suggestion much appreciated.
I see the exact question here:
Just add this to your code:
String.prototype.repeat = function( num )
{
return new Array( num + 1 ).join( this );
}
var str = "ABC";
console.log( str.repeat(5) ); // this will return `ABCABCABCABCABC`
Array.join. :D +1!String.prototype.duplicate = function( numTimes ){
var str = "";
for(var i=0;i<numTimes;i++){
str += this;
}
return str;
};
console.log( "abc".duplicate(2) );