I am new to StackOverflow so I apologize in advance for not being able to type everything structurally.
I have been trying for some time now to add an identifier to my array to use the .sort()
function of javascript to have the array content in alphabetical order. It is also important to not disassociate the amount with the name in the array.
My array contains the following when I use the console.log(result);
:
['0.4712', 'ARECIBO']
['0.5041', 'CAGUAS']
['0.4121', 'HUMACAO']
['0.4578', 'MAYAGUEZ']
['0.4785', 'PONCE']
['0.4038', 'SAN JUAN']
['0.4318', 'BAYAMON']
I have read many posts and have seen many users post this type of solution...
result.sort(function(a, b) {
return b[1] - a[0];
});
console.log(result);
Sadly, it does not work for me. I strongly believe that not only is my lack of knowledge an impeding factor, but also my lack of identifier in my array. Therefore, I implore your knowledge to solve this issue. If you can provide a brief explanation as to how the solution works, I would be grateful since it helps me grow and understand what I am doing.
Thank you all!