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 in alphabetical order. I tried using an easy way to sort the bubbles to do this. But it shows an error: "wrappedCompareFn is not a function."
function sort(arr1){
for(var i=0;i<arr1.length;i++){
for(var j=0;j<arr1.length;j++){
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?
source
share