let arr = [1, 2, 3];

arr.slice().reverse().forEach(x => console.log(x))

will print:

3
2
1

arr will still be [1, 2, 3], the .slice() creates a shallow copy.

Answer from naartjie on Stack Overflow
🌐
TutorialsTonight
tutorialstonight.com › foreach-reverse-javascript
Reverse forEach Loop JavaScript (with Examples)
You can see above that the forEach loop outputs the element of the array in reverse order.
🌐
LabEx
labex.io › tutorials › javascript-reverse-iteration-with-foreachright-28314
JavaScript forEachRight Function | Reverse Array Iteration | LabEx
Reverse the cloned array using Array.prototype.reverse(). Use Array.prototype.forEach() to iterate over the reversed array.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-loop-object-reverse-order
Loop through Object in Reverse Order using JavaScript | bobbyhadz
Call the reverse() method to reverse the array. Use the forEach() method to iterate over the array and access the object's keys and values in reverse order.
🌐
Codecademy Forums
discuss.codecademy.com › get help › javascript
Possible to Reverse .forEach()? - JavaScript - Codecademy Forums
September 25, 2018 - So I’ve been working on another classic beginners’ exercise, displaying array elements in reverse order without altering the string itself (why is there this stipulation, though? Is it somehow even easier to accomplish …
🌐
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().
🌐
Flexiple
flexiple.com › javascript › reverse-javascript-array
JavaScript: Reverse an array using different methods - Flexiple
March 11, 2022 - As the name suggests, this method reverses the order of array elements by modifying the existing array. ... arr = [1, 2, 3, 4]; arr1 = []; for (let i = arr.length - 1; i >= 0; i--) { arr1.push(arr[i]); } console.log(arr1); //Output: [4, 3, 2, ...
🌐
W3Schools
w3schools.com › jsref › jsref_reverse.asp
JavaScript Array reverse() Method
Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
Find elsewhere
🌐
SitePoint
sitepoint.com › blog › javascript › jquery .each backwards (reverse it)
jquery .each backwards (reverse it) — SitePoint
February 12, 2024 - To reverse the order of DOM elements using jQuery, you can use the .get() method to convert the jQuery object into a true JavaScript array. Then, you can use the .reverse() method to reverse the order of the elements. Finally, you can use the .each() method to iterate over the reversed array ...
🌐
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 }
🌐
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.
🌐
Linux Hint
linuxhint.com › loop-through-object-in-reverse-order-using-javascript
Loop Through Object in Reverse Order Using JavaScript
November 20, 2022 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
xjavascript
xjavascript.com › blog › javascript-loop-through-array-backwards-with-foreach
How to Loop Backwards Through a JavaScript Array Using forEach Without Reversing It — xjavascript.com
Looping backwards through an array with forEach is simple once you master the reverse index formula: array.length - 1 - index. This method avoids mutation, saves memory, and aligns with functional programming patterns.
Top answer
1 of 5
40

Javascript objects don't have a guaranteed inherent order, so there doesn't exist a "reverse" order.

4.3.3 Object An object is a member of the type Object. It is an unordered collection of properties each of which contains a primitive value, object, or function. A function stored in a property of an object is called a method.

Browsers do seem to return the properties in the same order they were added to the object, but since this is not standard, you probably shouldn't rely on this behavior.

A simple function that calls a function for each property in reverse order as that given by the browser's for..in, is this:

// f is a function that has the obj as 'this' and the property name as first parameter
function reverseForIn(obj, f) {
  var arr = [];
  for (var key in obj) {
    // add hasOwnPropertyCheck if needed
    arr.push(key);
  }
  for (var i=arr.length-1; i>=0; i--) {
    f.call(obj, arr[i]);
  }
}

//usage
reverseForIn(obj, function(key){ console.log('KEY:', key, 'VALUE:', this[key]); });

Working JsBin: http://jsbin.com/aPoBAbE/1/edit

Again i say that the order of for..in is not guaranteed, so the reverse order is not guaranteed. Use with caution!

2 of 5
31

Why there is no one has mentioned Object.keys() ?

you can get Array of Object's properties ordered as it is, then you can reverse it or filter it as you want with Array methods .

let foo = {
  "one": "some",
  "two": "thing",
  "three": "else"
};

// Get REVERSED Array of Propirties
let properties = Object.keys(foo).reverse();
// "three"
// "two"
// "one"

// Then you could use .forEach / .map
properties.forEach(prop => console.log(`PropertyName: ${prop}, its Value: ${foo[prop]}`));

// PropertyName: three, its Value: else
// PropertyName: two, its Value: thing
// PropertyName: one, its Value: some

🌐
YouTube
youtube.com › watch
Reverse array in JavaScript using for loop - YouTube
To reverse an array while iterating with a for loop in JavaScript, you can start from the last index of the array and move backwards to the first index. This...
Published   February 14, 2025
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › toReversed
Array.prototype.toReversed() - JavaScript - MDN Web Docs
July 10, 2025 - The toReversed() method transposes the elements of the calling array object in reverse order and returns a new array.
🌐
Google Groups
groups.google.com › g › knockoutjs › c › O1IkZFJwNWY
foreach in reverse order
September 3, 2012 - I recently added a "reverse" option to my repeat binding. So then you could do this: <ul> <li data-bind="repeat: { foreach: items, reverse: true }" data-repeat-bind="text: $item().id"></li>
🌐
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.