JSFiddle - React, Tailwind, and code Playground
by Andrei_Boiangiu
JavaScript
var students = [{
firstName: 'Gogu',
lastName: 'Vasile'
}, {
firstName: 'Bebe',
lastName: 'Boiangiu'
}, {
firstName: 'Andrei',
lastName: 'Boiangiu'
}];
var sorteStudents = students.sort(function(a, b) {
if (a.lastName === b.lastName) {
if (a.firstName === b.firstName) {
return 0;
} else if (a.firstName < b.firstName) {
return -1;
} else {
return 1;
}
} else if (a.lastName < b.lastName) {
return -1;
} else {
return 1;
}
});
console.log(sorteStudents);