I have a for loop that generates html. I'd for this method to generate the elements randomly. Right now they are cardinally generated i.e. d1, d2, ... di. I want them to follow a random sequence i.e. d1, di, di-3, .. di-k.
for (let i = numberOfInputs; i < dlArray.length+numberOfInputs; i++){
html +='\t\t\t\t\t\t<tr>\n'
html += '\t\t\t\t\t\t<td id="row';
id = (1+i-numberOfInputs);
html += id;
html +='">\n';
html += '\t\t\t\t\t\t\t<div id=\"t';
html += id;
html +='" class=\"ltarget\">'
html +='</div>\n'
html +='\t\t\t\t\t\t</td >\n'
html +='\t\t\t\t\t\t<td id=\"d'
html += id
html += '\">\n'
html +=`\t\t\t\t\t\t\t${dlArray[i-numberOfInputs]}\n`;
html +='\t\t\t\t\t\t\t</td >\n'
html +='\t\t\t\t\t\t</tr>\n';
}
What can I try to accomplish this?
arr[i]instead ofi. (also there's no need to insert linebreak and tab characters in your HTML, you can use single quotes for inner quotes, and HTML string composition is bad practice in general. You also have a type I guess since you aren't opening the rows with a<tr>)