I am attempting to sort my topArr.sales from Greatest to Least.
I am using the .sort() method in order to try and accomplish this.
At the moment my console.log return value is identical to the original array and I am stuck on what I am doing wrong in order to accomplish my desired result.
My expected result is having the topArr return in order, from greatest to least. Here is am example of my desired result:
let topArr = [
{ sales: "494,927", store: "Online" },
{ sales: "418,883", store: "Walk in" },
{ sales: "48,883", store: "Retail Stores" },
{ sales: "28,883", store: "Appointments" },
]
Here is my code snippet:
let topArr = [
{ sales: "494,927", store: "Online" },
{ sales: "48,883", store: "Retail Stores" },
{ sales: "418,883", store: "Walk in" },
{ sales: "28,883", store: "Appointments" },
];
topArr.sort(function (a, b) {
return a.sales - b.sales;
});
console.log(topArr)
"494,927" - "48,883"producesNaN, which is not a useful comparison result.salesvalue? If so, change to an integer.