loop array backwards javascript

116

loop array backwards javascript -

let arr = [1, 2, 3];
arr.slice().reverse().forEach(x => console.log(x))

js loop backwards -

var arr =  [1, 2, 3, 4, 5];
 
for (var i = arr.length - 1; i >= 0; i--) {
    console.log(arr[i]);
}

javascript loop through using reverse for-loop -

var arr = [1, 2, 3, 4, 5];
 
for (var i = arr.length - 1; i >= 0; i--) {
    console.log(arr[i]);
}

javascript backwards loop array -

var arr = [1, 2, 3, 4, 5];
 
for (var i = arr.length - 1; i >= 0; i--) {
    arr[i]
}

javascript loop through array backward -

const array = ['blastoff', 1, 2, 3];

for (let index = array.length - 1; index >= 0; index--) {
  const element = array[index];
  console.log(element);
}
 Run code snippet

Comments

Submit
0 Comments