repeat

Repeat a string a specified number of times and return the concatenated result.

Usage

var repeat = require( '@stdlib/string/base/repeat' );

repeat( str, n )

Repeats a string n times and returns the concatenated result.

var str = repeat( 'a', 5 );
// returns 'aaaaa'

str = repeat( '', 100 );
// returns ''

str = repeat( 'beep', 0 );
// returns ''

Examples

var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var repeat = require( '@stdlib/string/base/repeat' );

var i;
for ( i = 0; i < 100; i++ ) {
    console.log( repeat( 'beep', discreteUniform( 0, 3 ) ) );
}
Did you find this page helpful?