Given a string "asdlfjsahdkljahskl"
and an array [1,2,3,1,7,2,1,2]
, the final output should be a
, sd
, lfj
, s
, ahdklja
, hs
, kl
.
I'm able to split the string, but I'm unsure how to compare the string and cut it according to the given array.
Here's the HTML code:
<button onclick="myFunction()">click me</button>
<p id="demo"></p>
JavaScript:
var width = [1,4,2,6,1,1,10,1];
function myFunction() {
var str = "abcdefghijklmnopqrstuvwxyz";
var res = str.split("");
for(var j=0; j.length;j++){
document.write(width[j]);
}
document.getElementById("demo").innerHTML = res;
}
Thank you for your assistance!