Iteration- Javascript [closed]

You can use a simple for-loop:

document.write("<h1>");
for (var i=namArLen-1; i>=0; i--) {
    document.write(namAr[i]);
}
document.write("</h1>");

For simplicity, there’s also the reverse function on arrays:

document.write("<h1>"+namAr.reverse().join("")+"</h1>");

Leave a Comment