I have an array of objects: let fruits = [ { id: 1, name: 'Banana' }, { id: 2, name: 'Apple' }, { id: 3, name: 'Cherry' } ]; How can I sort them by their name attribute?
@fpendovskiAug 12.2022 — #You can do that by writing your own compare callback function and using .sort() on the fruits array: function compare(a, b) { if (a.name b.name) { return 1; } return 0; }