Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js sort array

// student array 
let students = ['John', 'Jane', 'Mary', 'Mark', 'Bob'];

// sort the array in ascending order
students.sort();

// ? result = ['Bob', 'Jane', 'John', 'Mark', 'Mary']

// sort the array in descending order
students.sort().reverse();

// ? result = ['Mary', 'Mark', 'John', 'Jane', 'Bob']
Source by www.quora.com #
 
PREVIOUS NEXT
Tagged: #js #sort #array
ADD COMMENT
Topic
Name
9+8 =