Sort List in JavaScript

Posted by yhuang
Public (Editable by Users)
JavaScript
None
Edit
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort(); 
console.log(fruits);

fruits.reverse();     // Then reverse the order of the elements
console.log(fruits);

// Custom sort
var complexList = [{prop: 1}, {prop:100}, {prop:23}];
complexList.sort(function(a, b){return a.prop - b.prop});
console.log(complexList);