1 this.arrayPrepareKeys.sort(
function (arrayA, arrayB) {
return arrayA[0].length - arrayB[0].length;
} );
2.To sort an array into some order other than alphabetical, you must pass a comparison function as an argument to sort(). This function decides which of its two arguments should appear first in the sorted array. If the first argument should appear before the second, the comparison function should return a number less than zero. If the first argument should appear after the second in the sorted array, the function should return a number greater than zero. And if the two values are equivalent (i.e., if their order is irrelevant), the comparison function should return 0. So, for example, to sort array elements into numerical rather than alphabetical order, you might do this:
<script language="javascript">
document.write("<br/>");
var a = [33, 4, 1111, 222];
document.write(a+"<br/>");a.sort(); // Alphabetical order: