Reverse in javascript | Sololearn: Learn to code for FREE!

+3

Reverse in javascript

explain reverse method in javascript, ?

js

5/8/2020 9:04:52 AM

Shadman Sakib

10 Answers

New Answer

+5

Reverse method is used to reverse an array. const a = [1,2,3].reverse(); console.log(a);

+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 :))

+3

thanks for the answer ☺

+3

Bear in mind, reverse method mutates the input array. If you want unmutable input, try const reversed = [...arr].reverse();

+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.

+2

You may find answer in:- 1) https://www.javatpoint.com/javascript-array-reverse-method 2) https://www.w3schools.com/jsref/jsref_reverse.asp 3) https://www.geeksforgeeks.org/javascript-array-prototype-reverse/

0

0

why? errroooor

0

oh 😅 well

0