S
S
selbi2018-01-29 11:10:07
JavaScript
selbi, 2018-01-29 11:10:07

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

3 answer(s)
R
RidgeA, 2018-01-29
@selbi

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.

D
Dmitry Kuznetsov, 2018-01-29
@dima9595

As I know - sorting is done by key or by alphabetical order.

S
Sergey Sokolov, 2018-01-29
@sergiks

this list can be rearranged

Add a new sort key field to the array elements. When dragging, update values. Sort by this key on output.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question