I want to sort an array of objects based upon any of those object properties. But I want the original array left unchanged. Instead, I want to save the sort order of indexes in a separate array.
var source = [
{"a": 2, "b": 8, "c": 9},
{"a": 4, "b": 3, "c": 7},
{"a": 1, "b": 0, "c": 6}
]
var sortedIndexes;
SomeSortOfSortMethod("a", "asc");
// result of sortedIndexes containing indexes to source array:
// [2, 0, 1]
Any ideas how to do this? I can't use the built in javascript sort method because it changes source. I need to just capture what the sort would be and save that order as indexes to the source arry.