Answer the question
In order to leave comments, you need to log in
How to sort an array?
Dear Toaster users, please tell me how to sort an array that contains some words, and there is no clear sign of sorting. Example:
Array: ['Auto', 'Fairy Tale', 'Sky', 'Earth', 'Autumn']
How to sort it so that it looks like this:
Autumn
Sky
Auto
Fairy Tale
Earth
Also, this list can be rearranged, and the array, respectively need to be sorted depending on this list.
PS This is a simplified example, in fact there is an array of objects. I would like a solution in JS, but it will also work in PHP.
Answer the question
In order to leave comments, you need to log in
I understand that you need to sort the array depending on the position of the element in the external list?
Well, in the comparator and compare by the position of the element in the list.
As I know - sorting is done by key or by alphabetical order.
this list can be rearranged
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question