String repeat()
str.repeat(count)
str
is a stringrepeat
is function namecount
is an integer
repeat() method repeats the string str
by count
number of times, and returns the resulting string. repeat() does not modify the original string str
Examples
1. repeat the string
let str = 'apple';
let output = str.repeat(4);
console.log('Output : ' + output);
2. if n
is 0
, then repeat() returns an empty string
let str = 'apple';
let output = str.repeat(0);
console.log('Output : ' + output);
3. if n
is a negative value, then repeat() raises RangeError
let str = 'apple';
let output = str.repeat(-3);
console.log('Output : ' + output);