// For the sorting of an Array of Numbers
var tempArr = [2,4,11,3,9,18,15,10];
tempArr.sort(function(a,b){
return a-b;
});
Output :: [2,3,4,9,10,11,15,18];
// For the sorting of an Array of Characters;
var tempArr2 = ['a','c','g','s','d','b','e'];
tempArr2.sort();
Output :: ["a", "b", "c", "d", "e", "g", "s"]
So in there 2 examples this can be easily visible for sorting of an Array of numbers we need a call back function for sorting but sorting of characters is very straight forward just by calling .sort() method with the array variable.This code snippet is for Sorting of an Array looks like a very simple question but many programmers fail in this wrt Javascript.
