Suppose I have two arrays, for example:
var SortedArray = [25, 123, 2464, 112, 54, 51, 347, 4572, 634];
var ArrayToSort = [634, 25, 51, 123];
SortedArrayis an array containing the order of many elements. ArrayToSortcontains only some of the elements SortedArray, and each element of ArrayToSort, of course, is also in SortedArray.
What is the best way to sort ArrayToSort so that the elements in this array appear in the same order as SortedArray and get this result:
ArrayToSort = [25, 123, 51, 634];
Thanks.
source
share