I have here the data
var sampleArray = [
{ "Rating 1": -75 },
{ "Rating 2": -70 },
{ "Rating 3": 98 },
{ "Rating 4": -88 },
{ "Rating 5": 29 },
];
I want to sort it to output the following
- Highest rating
- Lowest rating
- Rating that is near 0 (if there are 2 results, the positive will be chosen example:-1,1 then 1 will be chosen)
I'm stuck on getting the second value only which is the rating. I've tried the following codes to check if I can get the rating, but it shows the entire value of array 0
function topProduct(productProfitArray) {
return productProfitArray[0];
}