var ar = ['ape', 'moose', 'Zebra', 'cow', 'Calf', 'Mountain Lion', 'goat'];
// invoke sort method on array, passing function inline
console.log( ar.sort(function (a, b) {
if ( a.toLowerCase() < b.toLowerCase() ) {
return -1;
} else if ( a.toLowerCase() > b.toLowerCase() ) {
return 1;
} else {
return 0;
}
} ) );
// [ "ape", "Calf", "cow", "goat", "moose", "Mountain Lion", "Zebra" ]