5/8/2020 9:04:52 AM
Reverse method is used to reverse an array.
const a = [1,2,3].reverse();
Consider this :
const array = [1,2,3,4,5];
console.log(array.reverse()); // 5,4,3,2,1
thanks for the answer ☺
Bear in mind, reverse method mutates the input array.
If you want unmutable input, try
const reversed = [...arr].reverse();
Actually, I was a bit wrong :))
const a = [1,2,3,4,5];
const b = a.reverse();
console.log(b); // 5,4,3,2,1
console.log(a); // 5,4,3,2,1
Both of the array will give the reversed array. Although a was supposed to be the same.
You may find answer in:-
oh 😅 well
Send us a message