I have an Inventory as shown below.
var arr1 = [
[21, "Bowling Ball"],
[2, "Dirty Sock"],
[1, "Hair Pin"],
[5, "Microphone"]
];
I want to sort the inventory alphabetically. I tried using a simple bubble sort technique to do it. But it shows an error-"wrappedCompareFn is not a function".
function sort(arr1){
//console.log("works");
for(var i=0;i<arr1.length;i++){
for(var j=0;j<arr1.length;j++){
// console.log(arr1[j][1].localeCompare(arr1[i][1]));
if(arr1[j][1].localeCompare(arr1[i][1])<0){
var tmp=arr1[i][1];
arr1[i][1]=arr1[j][1];
arr1[j][1]=tmp;
}
}
}
return arr1;
}
Is there a problem with my code?? Also is there a better way to sort multidimensional arrays with different types of objects??