About 161,000 results
Open links in new tab
  1. Loop through an array backward in JavaScript | Techie Delight

    Apr 19, 2024 · There are several methods to loop through the array in JavaScript in the reverse direction: 1. Using reverse for-loop. The standard approach is to loop backward using a for …

  2. Javascript - Loop through array backwards with forEach

    Aug 25, 2020 · Is there a way to loop backwards through an array using forEach (not any other kind of loop, I know how to do with with a for / standard ways) and without actually reversing …

  3. javascript - Why is iterating through an array backwards faster …

    Jan 1, 2012 · i > 0 is faster than i < arr.length and is occurring on each iteration of the loop. You can mitigate the difference with this: for (var i = 0, len = arr.length; i < len; ++i) {; } This is still …

  4. javascript - How do i loop through an array backwards ... - Stack Overflow

    Nov 4, 2021 · Simple, loop the other way. Instead of i++ use i--: for(i = 0; i < array.length; i++){ // do something with array[i] } // you go backwards: for(i = array.length - 1; i >= 0; i--){ // do …

  5. javascript loop through array backwards - The Poor Coder

    Mar 25, 2023 · There are different ways to loop through an array backwards in Javascript, we can use a for loop, while loop, or the forEach() method provided by arrays in ES6. Using a for loop. …

  6. ES6 — Reverse Iterable for an Array | by Cha - Medium

    Jul 15, 2017 · To iterate over an array, a for..of loop can be used like below: console.log(i); //outputs 1,2,3,4,5 . But what if we want to iterate over the array backwards? console.log(arr[i]);...

  7. Efficiently Looping A Javascript Array Backwards

    Mar 16, 2017 · Turns out, there are a lot of scary alternatives to looping an array in reverse (mostly on StackOverflow). Some people are proponents of decrementing and using while …

  8. JavaScript - iterate array backwards - Dirask

    In this article, we would like to show you how to iterate an array backwards in JavaScript. 1. Using for loop. In this example, we use a simple for loop to iterate the array from the last element …

  9. Iterating in a closed loop, forwards and backwards | HynekS

    It has to work both forwards and backwards! In this post, I'm going to write about "closed loop iteration," or how to use JavaScript to iterate over an array so that after reaching its last …

  10. while - JavaScript | MDN - MDN Web Docs

    Mar 13, 2025 · The while statement creates a loop that executes a specified statement as long as the test condition evaluates to true. The condition is evaluated before executing the statement.

  11. Some results have been removed
Refresh