If you want an equal interval, your loop is fine, you just need to fix the math for calculating the timeout:

const btn = document.getElementById('btn');
btn.addEventListener('click', function(){
  
    for (let index = 10; index > 0; index--) {
        setTimeout(() => {
            console.log(index)
        },  1000*(10-index));      
    }
})
<div class="app">
  <button id="btn">click</button>
</div>

That will count down from 10 to 1 once every second, just change the 1000 as needed if you want it to be faster or slower.

Note that the order of the loop doesn't actually matter here (aside from a few ms difference in execution time) since it's asynchronous - you could use a non-reversed loop and still get the same result to the human eye.

Answer from John Montgomery on Stack Overflow
Top answer
1 of 2
3

If you want an equal interval, your loop is fine, you just need to fix the math for calculating the timeout:

const btn = document.getElementById('btn');
btn.addEventListener('click', function(){
  
    for (let index = 10; index > 0; index--) {
        setTimeout(() => {
            console.log(index)
        },  1000*(10-index));      
    }
})
<div class="app">
  <button id="btn">click</button>
</div>

That will count down from 10 to 1 once every second, just change the 1000 as needed if you want it to be faster or slower.

Note that the order of the loop doesn't actually matter here (aside from a few ms difference in execution time) since it's asynchronous - you could use a non-reversed loop and still get the same result to the human eye.

2 of 2
1

If you use promises and async/await you can avoid the setTimeout overload and have precise control. The difference between this and John Montgomery's answer is this doesn't care how many times you loop. Do 10000 if you want, you won't get 10000 setTimeouts running at the same time.

const btn = document.getElementById('btn');
const wait = time=>new Promise(resolve=>setTimeout(resolve,time))
btn.addEventListener('click', async function(){      
    for (let index = 10; index > 0; index--) {
        await wait(1000)
        console.log(index)
    }
})
<div class="app">
  <button id="btn">click</button>
</div>

Async functions allow you to use the await keyword. This is a neat new feature in javascript that let's you write async code (like setTimout) as if it was sync.

const wait = time=>new Promise(resolve=>setTimeout(resolve,time)) is a fairly common helper function developers keep around for times you need to just wait some amount of time and then do something. By await'ing the wait(1000) function, I hang the execution of the loop until the time is done.

๐ŸŒ
Techie Delight
techiedelight.com โ€บ home โ€บ java โ€บ loop through an array backward in javascript
Loop through an array backward in JavaScript | Techie Delight
2 weeks ago - To avoid modifying the original array, first create a copy of the array, reverse the copy, and then use forEach on it. The array copy can be done using slicing or ES6 Spread operator. ... The reduceRight() method executes the callback function once for each element present in the array, from right-to-left. The following code example shows how to implement this. ... Thatโ€™s all about looping through an array backward in JavaScript.
๐ŸŒ
AlgoCademy
algocademy.com โ€บ link
Looping In Reverse in JavaScript | AlgoCademy
A for loop typically includes three ... Iteration: This updates the loop variable after each iteration. In a reverse loop, the iteration step usually involves decrementing the loop variable....
๐ŸŒ
DEV Community
dev.to โ€บ tpointtech123 โ€บ how-to-reverse-a-string-in-javascript-using-a-for-loop-1aof
How to Reverse a String in JavaScript Using a For Loop - DEV Community
March 20, 2025 - By starting from the last character of the string and working backward, you can append each character to a new string, effectively reversing it. This approach is efficient and easy to understand, making it a great practice for beginner developers.
๐ŸŒ
Code Highlights
code-hl.com โ€บ home โ€บ javascript โ€บ tutorials
7 Powerful Tips for JavaScript Reverse For Loop Mastery | Code Highlights
September 11, 2024 - This example shows how to modify elements of an array while looping in reverse. The output will be [10, 8, 6, 4, 2]. ... In this case, we build a new string by adding characters in reverse order. ... This example shows how to iterate over object properties in reverse order. Most modern web browsers support the JavaScript reverse for loop.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-reverse-an-array-in-javascript-js-reverse-function
How to Reverse an Array in JavaScript โ€“ JS .reverse() Function
November 29, 2022 - Using a for loop (or any other type of loop), we can loop through an array from the last time to the first item, and push those values to a new array which becomes the reversed version.
๐ŸŒ
Chidrestechtutorials
chidrestechtutorials.com โ€บ web โ€บ javascript โ€บ reverse-for-loop.html
JavaScript reverse for loop
JavaScript reverse for loop to display the multiplication table in reverse order: for(var i=10; i>=1; i--) { document.write(2," x ",i," = ",2*i,"<br/>"); }
Find elsewhere
๐ŸŒ
Log4JavaScript
log4javascript.org โ€บ home โ€บ js-framework โ€บ mastering backward iteration with for loops in javascript
Reverse Number in JavaScript Using For Loop: A Guide
October 24, 2023 - Learn the art of executing for loops in the opposite direction in JavaScript. This in-depth guide offers multiple illustrations, best practices, and use cases.
๐ŸŒ
YouTube
youtube.com โ€บ watch
JavaScript for Beginners #40 Looping Backwards - YouTube
Here, we will learn how to loop backwards with a for loop. This may be useful if want to loop through an array backwards. 0:00 Looping through a for loop bac...
Published ย  February 16, 2021
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_reverse.asp
JavaScript Array reverse() Method
The reverse() method reverses the order of the elements in an array.
๐ŸŒ
Medium
josephcardillo.medium.com โ€บ how-to-reverse-arrays-in-javascript-without-using-reverse-ae995904efbe
How to Reverse Arrays in JavaScript Without Using .reverse() | by Joe Cardillo | Medium
January 31, 2022 - We started at the beginning of the array in our for loop. We moved through the array until we reached the halfway point. With each loop we set the element at i โ€” or arr[i] โ€” equal to a variable called el. Then we set the first element equal to the last, and the last element equal to the first. With each subsequent loop, as we moved inward we did the same thing. Iโ€™m a JavaScript rookie, so if you have a more efficient way of doing this Iโ€™d love to hear from you in the comments section below!
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ javascript-loop-object-reverse-order
Loop through Object in Reverse Order using JavaScript | bobbyhadz
Copied!const obj = { a: 'one', b: 'two', c: 'three', }; // ๐Ÿ‘‡๏ธ ['c', 'b', 'a'] const reversedKeys = Object.keys(obj).reverse(); reversedKeys.forEach(key => { console.log(key, obj[key]); // ๐Ÿ‘‰๏ธ c three, b two, a one }); ... The first step is to get an array of the object's keys by using the Object.keys() method. ... Copied!const obj = { a: 'one', b: 'two', c: 'three', }; const keys = Object.keys(obj); console.log(keys); // ๐Ÿ‘‰๏ธ ['a', 'b','c'] The Object.keys() method returns the object's keys ordered in the same way as given by looping over the object's properties manually.
๐ŸŒ
Medium
oliviacodes.medium.com โ€บ reverse-an-array-in-javascript-using-a-for-loop-27f709ea3c4a
Reverse an Array in JavaScript using a For Loop | by Olivia | Medium
June 3, 2021 - [11, 5, 19, 98]has a length of 4 elements inside the array but indexes start from 0, so its index is 0, 1, 2, 3 โ€” we minus 1 from the length to account for the fact array indexes start at 0 ... there will be no element / number at index [-1], but there is one at index[0], so donโ€™t need to go into negative numbers. stop at 0. ... This is a way of decrementing i on each iteration, if 3 is starting at 3, on iteration it will go: 3, 2, 1, 0. Remember our loop will not get to -1!
๐ŸŒ
Sololearn
sololearn.com โ€บ en โ€บ Discuss โ€บ 981326 โ€บ how-to-reverse-a-number-in-a-for-loop
How to reverse a number in a FOR loop | Sololearn: Learn to code for FREE!
... Thanks everyone - I did not ... correct output: function reverse(num){ var reversedNum = 0; for(var i = num.length - 1; i >= 0; i--){ reversedNum = reversedNum + num[i]; } return parseInt(reversedNum); } console.log(reve...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ reverse-array-with-for-loops-javascript
Reverse array with for loops JavaScript
August 21, 2020 - We have to write a function that takes in an array and returns its reverse. Find its reverse using the for loop. Our sample array โˆ’ const arr = [7, 2, 3, 4, 5, 7, 8, 12, -12, 43, 6]; So, let&r
๐ŸŒ
Medium
medium.com โ€บ @chanakyabhardwaj โ€บ es6-reverse-iterable-for-an-array-5dae91c02904
ES6 โ€” Reverse Iterable for an Array | by Cha | Medium
July 15, 2017 - let arr = [1,2,3,4,5]; let index = arr.length;//Custom Iterator let reversedIterator = { next : function () { index--; return { done : index < 0, value : arr[index] } } }//Make it an Iterable reversedIterator[Symbol.iterator] = function() { return this; }for (let i of reversedIterator) { console.log(i); //outputs 5,4,3,2,1 }