Javascript Array.prototype.sort() method, anyone?

Just for the sake of utter simplicity I would also add to ead’s comment, as from the MDN docs, if you want true ‘alphabetical order sort’ (assuming case and punctuation are removed), simply just array.sort() will work without need for any compare function.

i know it but what if you want to sort not an array of strings but an array of objects or a nested array i.e. an array of arrays by the alphabetical order of a property of those objects or a value by one of the indexes in those inner arrays? btw in the challenge “inventory update” as one of the tasks you have to do exactly that, you have to alphabetically sort a nested array. so sometimes you still need callback to sort strings, you have to use for instance a[1] and b[1] there ofc, assuming you sort by the index 1 value

you also may save the anonymous callback as a separate function like
function mySort (a, b) {return a > b;}
and then you can use it like arr.sort(mySort) and the arr now can be both of numbers or of strings and it will be sorted properly anyway. tbh javascript had to make sort() work by default like that but w/e