string repeat
var a="a";
var aaa=a.repeat(3); // "aaa"
function repeatStringNumTimes(string, times) {
var repeatedString = "";
while (times > 0) {
repeatedString += string;
times--;
}
return repeatedString;
}
repeatStringNumTimes("abc", 3);repeatStr = (n, s) => s.repeat(n);// hey buddy, here are different implementations, choose your favourite !!
// best implementation
repeatStr = (n, s) => s.repeat(n);
// short
function repeatStr(n, s) {
return s.repeat(n);
}
// without using repeat
function repeatStr(n, s) {
var str = "";
for (var i = 0; i < n; i++) str += s;
return str;
}
Also in JavaScript:
- bootstrap checkbox
- javascript regex reference
- how click button and redirect angular
- array in javascript
- class to functional component react
- javascript get first 10 characters of string
- acces store from vue console javascript
- angular stoppropagatio
- how to check string uppercase or lowersace using regex javascript
- get an element from outside of iframe jquery
- get value of input element on button click react
- too many open files react native
- npm err! 503 service unavailable proxy
- javjquery is emptyobject
- javascript add button to div
- js slice
- javascript alert program
- click anchor tag using jquery
- nodejs format text
- how to get a due date from current date in javascript
- json stringify recursive
- deduplicate array javascript
- ajax call
- viewdata array mvc razor javascript