I have an array (myarray) which contains mixed case values ranging alphabets from a, A , ... z,Z. I am using the following mechanism to sort it irrespective of case that means all capital letters should come first as sorted and then the lowercase ones so that it looks like below after sorting :
Abc, Abd, abs, abp, Back, Bann, bike, ... and so on
I am doing it following way,
var myarray= new Array();
for (i=0; i<select.options.length; i++) {
myarray[i] = new Array();
myarray[i][0] = select.options[i].text;
myarray[i][1] = select.options[i].value;
}
myarray.sort(function (a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
});
But I am getting the following error :
TypeError: a.toLowerCase is not a function
I am using the most commonly used function but still getting that above error and not finding any solution. Please help me with a better approach or point out what mistake I am making to get that error.
thanks.
a?toLowerCaseis a method ofString. Your array probably contains something else.