MV Sorting the content of an array

I have ID's recorded in an array. Each ID represents a card, and those are unlocked in a random order.
So an array might look like this:
var3 = [4,1,3,6,7,4,2,1]

I want to to sort the entrees to become
var3 = [1,1,2,3,4,4,6,7]

Is there a simple script call that makes this happen?

I know, this is probably very basic javascript, but I can't seem to figure this one out. 😛
1700436968088.png
This should come with a very big caveat that it sorts those numbers alphabetically, which will mysteriously break once you introduce IDs larger than 10.
1700437506938.png


To sort them numerically, do:
1700437556500.png
This should come with a very big caveat that it sorts those numbers alphabetically, which will mysteriously break once you introduce IDs larger than 10.
View attachment 284412

To sort them numerically, do:
View attachment 284413
That's a fair point, I forgot to mention that. ^_^
This should come with a very big caveat that it sorts those numbers alphabetically, which will mysteriously break once you introduce IDs larger than 10.
View attachment 284412

To sort them numerically, do:
View attachment 284413
Seems to work perfectly. Thanks to both of you.
or make your own function to compare an array:
JavaScript:
function NrCompare(a, b) {
    if (a > b) {
        return 1;
    } else if (a < b) {
        return -1;
    } else {
        return 0
    }
}
than you could do NrCompare(44,33)
of for array:
let array = [3,45,44,93,12,2]
array.sort(NrCompare)

so it will do it also for you if you need it tiny bit more complex, but
Mac15001900 works as well, maybe most of the time ^^

depends what you really need 😉

I use this function for my own under a different name though.

Original thread: https://forums.rpgmakerweb.com/threads/sorting-the-content-of-an-array.163081/