html - Repeat a function in Javascript with .length -
i have long string.
var string = "this long string." i have function download string "path".
downloadfunction{... 'echo "'+string+'" >> '+path;} how execute function every 2 letters of string? read somewhere using ".length" not sure how implement in case. not want split string array. download function should split string download 2 letters progressively.
i.e. download string 2 letters @ time.
edit: clarify, string needs downloaded x characters @ time download break if exceeds limit.
here example commented on how this:
var string = 'a really long string \ want split 2 letters @ time'; // needs ceiling rounds on odd numbers // otherwise last letter may left out var iterations = math.ceil(string.length / 2); (var = 0; < iterations; i++) { // iterating on half of length want go 2 letters @ time var j = i*2; // make new string first letter var letters = string[j] // if statement check if there second letter // if there concat first letter // otherwise last set of odd length concat `undefined` if (string[j+1]) { letters += string[j+1]; } // call function here passing `letters` downloadfunction{... 'echo "' + letters + '" >> '+path;} }
Comments
Post a Comment