JSFiddle - React, Tailwind, and code Playground
by sergiu079
JavaScript
var students=[{
firstName: 'Dan',
lastName: 'Ionescu'
}, {
firstName: 'George',
lastName: 'Alexandrescu'
}];
var sortedStudents = students.sort(function(a, b){
if (a.lastName === b.lastName) {
return 0;
} else if (a.lastName < b.lastName) {
return -1;
} else {
return 1;
}
});
console.log(sortedStudents);