0

I have an array a=["Apple","Mango","apple","mango"] .If I use the a.sort() the result is ["Apple", "Mango", "apple", "mango"]

But What i desire is

Apple,apple,Mango,mango

Remember It is not case inSesitive search as whatever the order of given element in the array be ,the output should be as

Apple apple Mango mango Means the capital letter should precedes the smaller one

Roshan
  • 2,144
  • 2
  • 16
  • 28

1 Answers1

0

Use This

function alphabetical(a, b)
{
     var A = a.toLowerCase();
     var B = b.toLowerCase();
     if (A < B){
        return -1;
     }else if (A > B){
       return  1;
     }else{
       return 0;
     }
}

$(document).ready(function(){
var colors = new Array("Apple","Mango","apple","mango");

colors.sort(alphabetical);

var cj = colors.join(", ");
alert(cj);
})

DEMO

cracker
  • 4,900
  • 3
  • 23
  • 41