Is it possible to sort arrays based upon a previous sort?

I have several arrays with differnt data inside of them. for example, firstname, lastname etc. Could I run an Array.Sort() to put one of the arrays in a alphabetical order and then use that sorting data to apply to the other arrays thus keeping all of the data aligned? I am using Javascript. I am also trying to avoid too many ‘for’ loops if possible?

I guess the first question is why are you using multiple arrays? You should have a class or a struct defined with firstname, lastname etc then there would be one array that you could sort and all of the data would be kept together.

If you insist on having multiple arrays then you need another array of ints which is the index into the other arrays - sort this using the lookup to lastname (or whatever) then use it to get to the entries in all of the arrays.

If you use Linq you can do both noraml and multikey sorting in Javascript.

It’s best not to use multiple parallel arrays; it’s a much better idea to create a class that has firstname, lastname, etc. and make an array of that class. You can create a custom sort function based on whatever criteria.

class NameData {
    var firstName : String;
    var lastName : String;
    function NameData (firstName : String, lastName : String) {
        this.firstName = firstName;
        this.lastName = lastName;

function LastNameSort (a : NameData, b : NameData) {
    return System.String.Compare (a.lastName, b.lastName);

function Awake () {
    var folks = [NameData("John", "Smith"), NameData("Jane", "Doe")];
    System.Array.Sort (folks, LastNameSort);
    print (folks[0].firstName);