Sort method in array


Overview

sort method is used to sort the elements of array in term of their occurrences.

Code


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

Run

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