How to use repeat() to repeat a string and get new string which contains the of copies of a string in JavaScript

1 Answer

0 votes
document.write('abc'.repeat(1) + "<br />");
document.write('abc'.repeat(2) + "<br />");
document.write('abc'.repeat(3) + "<br />");
document.write('abc'.repeat(2.5) + "<br />");
document.write('abc'.repeat(0) + "<br />");
document.write('abc'.repeat(-1) + "<br />"); // Error


/*
run:

abc
abcabc
abcabcabc
abcabc

*/

 



answered Aug 10, 2016 by avibootz
...