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
🌐
AlgoCademy
algocademy.com › link
Looping In Reverse in JavaScript | AlgoCademy
In this lesson, we will explore how to use a for loop to count backwards in JavaScript. Looping in reverse is a common requirement in programming, especially when you need to process elements in reverse order or when decrementing values.
🌐
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.
Discussions

Reverse for loop in JavaScript - Stack Overflow
More info on that can be found in this article, "Understanding setTimeout Inside For Loop in JavaScript". More on stackoverflow.com
🌐 stackoverflow.com
javascript - How to reverse the order in a FOR loop - Stack Overflow
I've a simple FOR statement like this: var num = 10, reverse = false; for(i=0;i More on stackoverflow.com
🌐 stackoverflow.com
For loop backwards
The instructions state the following… We need to make three changes to our for loop: Edit the start condition (var i = 0), to set i equal to the length of the vacationSpots array. Then, set the stop condition ( i < vacationSpots.length) to stop when i is greater than or equal to 0. Finally, ... More on discuss.codecademy.com
🌐 discuss.codecademy.com
1
0
October 10, 2017
javascript - Are loops really faster in reverse? - Stack Overflow
Are JavaScript loops really faster when counting backward? If so, why? I've seen a few test suite examples showing that reversed loops are quicker, but I can't find any explanation as to why! I'm assuming it's because the loop no longer has to evaluate a property each time it checks to see if it's finished and it just checks against the final numeric value. ... for ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 - This post will discuss how to loop through an array backward in JavaScript... The standard approach is to loop backward using a for-loop starting from the end of the array towards the beginning of the array.
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.

🌐
Coderwall
coderwall.com › p › wnbixq › an-elegant-way-to-do-reverse-order-c-style-for-loops
An elegant way to do reverse order C-style for loops (Example)
February 25, 2016 - This is awesome because it looks like an arrow i --> 0 but actually you are decrementing i after testing i>0. C/C++ programmers probably knew this already, but I bet there are some web devs out there that will find this as cool as I did. Just don't forget the second semicolon (basically you are leaving the third argument, the code to run at the end of each loop, blank).
🌐
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 - Append each character to the new string in reverse order. Return the newly constructed string. Let’s implement this using a for loop in JavaScript.
🌐
TutorialsPoint
tutorialspoint.com › reverse-array-with-for-loops-javascript
Reverse array with for loops JavaScript
August 21, 2020 - Find its reverse using the for loop. ... const arr = [7, 2, 3, 4, 5, 7, 8, 12, -12, 43, 6]; const reverse =(arr) => { const duplicate = arr.slice(); const reversedArray = []; const { length } = arr; for(let i = 0; i < length; i++){ reversedArray.push(duplicate.pop()); }; return reversedArray; }; console.log(reverse(arr));
Find elsewhere
🌐
Code Highlights
code-hl.com › home › javascript › tutorials
7 Powerful Tips for JavaScript Reverse For Loop Mastery | Code Highlights
September 11, 2024 - How to reverse using for loop? Start from the last index and loop until the first index. Is there a reverse method in JavaScript? Yes, the reverse() method is available for arrays.
🌐
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!
//Try this. function reverse(num){ num+="" var reversedNum = ""; for(var i = num.length - 1; i >= 0; i--){ reversedNum = reversedNum + num[i]; } return reversedNum; } console.log(reverse(1234)); ... // This uses string to get reversedNum function ...
🌐
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 - In this case, the array’s length property helps identify the terminal index, enabling the loop to proceed in a descending fashion through the array elements. The use of length lets you start at the array’s last index and work your way backward, thanks to the decrement operation. Running ‘for loops’ in reverse in JavaScript isn’t merely a programming curiosity; it’s a practical skill with direct applications in areas like data manipulation and algorithm optimization.
🌐
SheCodes
shecodes.io › athena › 76786-javascript-for-loop-examples-array-iteration-and-reverse-order
[JavaScript] - JavaScript For Loop Examples: Array Iteration and Reverse Order
Learn how to use a for loop in JavaScript with examples for iterating through an array and looping in reverse order. ... arithmetic operators JavaScript addition subtraction multiplication division modulus programming coding basics
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › array › iterate over array in reverse
Iterate over a JavaScript array from right to left - 30 seconds of code
October 10, 2023 - const forEachRight = (arr, callback) => arr.slice().reverse().forEach(callback); forEachRight([1, 2, 3, 4], val => console.log(val)); // '4', '3', '2', '1' ... Learn how to get the first or last N elements of a JavaScript array, using Array.prototype.slice().
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › javascript faq
FAQ: Loops - Looping in Reverse - Page 2 - JavaScript FAQ - Codecademy Forums
September 27, 2020 - This community-built FAQ covers the “Looping in Reverse” exercise from the lesson “Loops”. Paths and Courses This exercise can be found in the following Codecademy content: Web Development Introduction To JavaScr…
🌐
W3Schools
w3schools.com › jsref › jsref_reverse.asp
JavaScript Array reverse() Method
The reverse() method overwrites the original array. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make ...
Top answer
1 of 10
3

pop (MDN, spec) is a mutator method: It changes the state of the array you call it on. So naturally, inArr.pop(1) modifies arr (in your first example), since inArr and arr both refer to the same array.

Probably worth noting as well that pop doesn't accept any parameters, so that 1 doesn't do anything.

In your first example, your best bet is to just assign another variable (say, j) the initial value arr.length - 1 and use arr[j] to get the value, then decrease j as you increase i. (Also, no point to inArr, and you need to declare i to avoid what I call The Horror of Implicit Globals:

function reverseArray (arr) {
    var newArr = [];
    for (var i = 0, j = arr.length - 1; i < arr.length; i++, j--) {      
        newArr[i] = arr[j];
    }   
    return newArr;
}
console.log(reverseArray(["A", "B", "C", "D", "E", "F"]));

You can also just use arr[arr.length - i - 1] rather than a second variable:

function reverseArray (arr) {
    var newArr = [];
    for (var i = 0; i < arr.length; i++) {      
        newArr[i] = arr[arr.length - i - 1];
    }   
    return newArr;
}
console.log(reverseArray(["A", "B", "C", "D", "E", "F"]));

2 of 10
3

You could take a copy of the array and use the length of the copy for checking the next pop/push command.

function reverseArray(array) {
    var newArr = [],
        inArr = array.slice();    // take copy of primitive values

    while (inArr.length) {        // check decrementing length
        newArr.push(inArr.pop());
    }
    return newArr;
}

console.log(reverseArray(["A", "B", "C", "D", "E", "F"]));

To fullfill the condition, you could use a for statement as well.

function reverseArray(array) {
    var newArr = [],
        inArr = array.slice();    // take copy of primitive values

    for(; inArr.length; ) {       // check decrementing length
        newArr.push(inArr.pop());
    }
    return newArr;
}

console.log(reverseArray(["A", "B", "C", "D", "E", "F"]));