I am trying to sort one array, but have a second array stay in sync with the first.
Example:
var a1 = ["human", "animal", "plant"];
var a2 = ["person", "beast", "nature"];
a1.sort();
After the sort I need to arrays to look like this:
a1 = ["animal", "human", "plant"];
a2 = ["beast", "person", "nature"];
Is there an easy way to do this, Maybe using a custom sort function?
You could zip the arrays before sorting, and unzip them after sorting:
…but I think @duffymo’s got a better suggestion for you. Use an object/hash/associative array/map.