reverse method in array


Overview

reverse method is used to reverse the order of the array such that the first element becomes the last and the last element becomes the first

Code


													
//Name of the file : array-reverse.js
arr = ['b','e','a','o','p','n','r'];
console.log(arr);
arr.reverse();
console.log(arr);		
													
												

Run

  • Now run the snippet using the following command :
    													
    >node array-reverse.js
    [ 'b', 'e', 'a', 'o', 'p', 'n', 'r' ]
    [ 'r', 'n', 'p', 'o', 'a', 'e', 'b' ]