JSFiddle - React, Tailwind, and code Playground
JavaScript
(function() {
var productList = {
"products": [
{
"description": "Product 1",
"price": "3.25"
},
{
"description": "Product 4",
"price": "9.97"
},
{
"description": "Product 3",
"price": "4.21"
},
{
"description": "Product 2",
"price": "5.24"
},
{
"description": "Product 5",
"price": "8.52"
}
]
};
var sortByPrice = function(a, b) {
//compare a to b, return integer. Negative means <, 0 means ===, positive is >
return a.price - b.price;
};
console.log(productList.products.sort(sortByPrice));
}());