Array.sort(function(a, b) {
return a — b;
return b — a;
});
const student = [
{ name : “재석”, age : 21},
{ name : “광희”, age : 25},
{ name : “형돈”, age : 13},
{ name : “명수”, age : 44}
]
student.sort(function(a, b) {
return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;
});
student.sort(function(a, b) {
return a.name > b.name ? -1 : a.name < b.name ? 1 : 0;
});
const sortingField = “age”;
student.sort(function(a, b) {
return a[sortingField] — b[sortingField];
});
student.sort(function(a, b) {
return b[sortingField] — a[sortingField];
});