Program to use JavaScript Array reverse() method
let a = [1,2,3,4,5];
let b = a.reverse();
console.log(b);
Output
[ 5, 4, 3, 2, 1 ]
Steps Description
- Declare two variable
a
andb
- Initialize two variable with value of array
a = [1,2,3,4,5]
andb = a.reverse()
- The
array reverse()
method returns the given array in reverse order of the array elements. - The value of
b
variable is displayed with the help of console.log inbuilt function
Program to use JavaScript Array reverse() method
let c = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant'];
let d = c.reverse();
console.log(d);
Output
[ 'Elephant', 'Lion', 'Tiger', 'Dog', 'Cat' ]
Steps Description
- Declare two variable
c
andd
- Initialize two variable with value of array
c = ['Cat', 'Dog', 'Tiger', 'Lion', 'Elephant']
andd = c.reverse()
- The
array reverse()
method returns the given array in reverse order of the array elements. - The value of
d
variable is displayed with the help of console.log inbuilt function