javascript integer comparitor function code example
Example 1: sort array of objects javascript
list.sort((a, b) => (a.color > b.color) ? 1 : -1)
Example 2: javascript sort
var names = ["Peter", "Emma", "Jack", "Mia", "Eric"];
names.sort();
var objs = [
{name: "Peter", age: 35},
{name: "Emma", age: 21},
{name: "Jack", age: 53}
];
objs.sort(function(a, b) {
return a.age - b.age;
});
Example 3: arr.sort
var fruitSalad = ['cherries', 'apples', 'bananas'];
fruit.sort();
var scores = [1, 10, 2, 21];
scores.sort();
var randomThings = ['word', 'Word', '1 Word', '2 Words'];
randomThings.sort();