+ 3

Reverse in javascript

explain reverse method in javascript, ?

8th May 2020, 9:04 AM
Shadman Sakib
Shadman Sakib - avatar
10 Respostas
+ 5
Reverse method is used to reverse an array. const a = [1,2,3].reverse(); console.log(a);
8th May 2020, 9:07 AM
Raj Chhatrala
Raj Chhatrala - avatar
+ 4
Consider this : const array = [1,2,3,4,5]; console.log(array.reverse()); // 5,4,3,2,1 reverse() method is used to reverse an array in javascript :))
8th May 2020, 9:07 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 3
thanks for the answer ☺
8th May 2020, 9:08 AM
Shadman Sakib
Shadman Sakib - avatar
+ 3
Bear in mind, reverse method mutates the input array. If you want unmutable input, try const reversed = [...arr].reverse();
8th May 2020, 9:32 AM
Calviղ
Calviղ - avatar
+ 3
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.
8th May 2020, 9:42 AM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
0
ok
8th May 2020, 9:33 AM
Shadman Sakib
Shadman Sakib - avatar
0
why? errroooor
8th May 2020, 9:34 AM
Shadman Sakib
Shadman Sakib - avatar
0
oh 😅 well
8th May 2020, 9:43 AM
Shadman Sakib
Shadman Sakib - avatar
0
welllll
9th May 2020, 3:47 PM
Shadman Sakib
Shadman Sakib - avatar