let arr = [1,2,3]
let newArr = arr.slice().reverse(); //returns a reversed array without modifying the original
console.log(arr, newArr) //[1,2,3] [3,2,1]
//The reverse() method reverses the elements in an array.
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.reverse();
//output >> ["Mango", "Apple", "Orange", "Banana"]
//if you find the answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
// reversing an array in javascript is kinda hard. you can't index -1.
// but i can show how you can do it in 4 lines.
var myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
for (var i = myArray.length - 1; i > 0; i -= 1) {
myArray.shift();
myArray.push(i);
}
console.log(myArray); // output: [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
const reverseArray = (arr)=>{
for (let v = arr.length ; v > 0 ; v--) {
return arr[v];
}
}
//if you find this answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)