Example of the JSON I'm trying to sort:
{
"auctions": [{
"uuid": "533cbc92429c4456b2c013607eed5c38",
"auctioneer": "5ba9f43481854fe891f94dfbd771b065",
"profile_id": "4bec273ae4fa4ebd80169b734d0702bc",
"coop": ["5ba9f43481854fe891f94dfbd771b065"],
"start": 1600978137016,
"end": 1600999737016,
"item_name": "Hologram",
"item_lore": "§8Furniture\n§8Colored\n\n§7Add some flare to your island\n§7with custom floating text!\n\n§6§lLEGENDARY",
"extra": "Hologram Skull Item",
"category": "misc",
"tier": "LEGENDARY",
"starting_bid": 300000,
"item_bytes": "H4sIAAAAAAAAAE1Ry26bQBS9dtIG01b5gkpUyhYFbAOmUheWTQKWAcfPmE01mIGMMwMWDE3wP/Q7vO03+MOqTtpNV1f3nHPPfckAHWgRGQBabWiTpPWzBe9GRZ3zlgwXHGUX0HFJgu8oyiqh+i2DvHiuKQ1fclxK0PYSuNGsLsYxMlUr1W21Z5qGag+6qYoslMZmjLAV66JuVhYHXHKCqw5IHL/yusTV39YSvFsjWmP4hZuJFj0+acnjhO4azxT5cqHR0NsfLC9fN/HIMz0meHdoThv7P63B0cag297kKcof6pittWlvTrE713ds9SMcJzRazmkwzoxg4xjbY0T9/cPR/xe7wX69D5bbYzj2ej5zjhFb0+3GN4Llqh+OJyzaPzfbzero7x1dxF5EJnb6qH0T08twlZDqQFHTgctpUWJJgFfw8Xwa3NVlTt7WBFlko4IKNhGscj5ZwyRRqoJhJaWoxAovlKaoS4VUFOUJfBaKF8KflF1d8YIJUYE4yTPl7W5fhMX1+WSeT3Tq3DvBeDjfSnAZIIbhg8Bd0SgrEROjXTuvvERDzksS1xxXEnSKkmQkX6IMPi3ccPZ9tpqP3OHCkd7+D5IbTsP7+dAXhnUtgBsztZHdTRM11nWk9gcWVm1s9NXdzhzocZrEtqEJW04YrjhiB7i2b7v9266m9L9qA2XmA7Th/RgxlGG4APgDfkDxxHQCAAA=",
"claimed": false,
"claimed_bidders": [],
"highest_bid_amount": 0,
"bin": true,
"bids": []
}, {
"uuid": "4803a8c0e1674dfb9bf7581975d6181f",
"auctioneer": "aa277b630ed94690905b955024e4ae21",
"profile_id": "16df394a108042a18c32a57684369aac",
"coop": ["b00fc41206a74e5886767298081ff151", "aa277b630ed94690905b955024e4ae21", "ab8012ba98fa46d994e393406a0cccd5", "9680e1dd20aa4e01b0bb79e6413983fe"],
"start": 1600977772109,
"end": 1600999372109,
"item_name": "Hologram",
"item_lore": "§8Furniture\n§8Colored\n\n§7Add some flare to your island\n§7with custom floating text!\n\n§6§lLEGENDÄR",
"extra": "Hologram Skull Item",
"category": "misc",
"tier": "LEGENDARY",
"starting_bid": 399999,
"item_bytes": "H4sIAAAAAAAAAE1Ry26bQBS9dpIG01b5gkpUyhYFPwATqQvLJgHLgOO32VSDGZNxZsCCoQled9vv8Lbf4P5X1XG76erqnnPuuS8ZoAE1IgNArQ51Etd+1OCqn5Upr8lwwVFyAQ2HxPiBoqQQqt8yyNOXktLgNcW5BHU3hlvNbGEcIUM1t01LbRuGrlrd1lZFJtpGRoSwGTVF3TjP9jjnBBcNkDh+42WOi7+tJbhaIFpi+ImroRaunrV4NaSbyjVEPptqNHB3e9NNF1XUdw2XCd7pGaPK+k+rc7TU6bo9fA7TpzJiC23UnlDsTJobNv8WDGIazibUHyS6v7T19SGk3u7p4P2LLX+32Pmz9SEYuG2P2YeQLeh66en+bN4JBkMW7l6q9XJ+8HZ2U8R2SIbWdqV9EdPLcB2TYk9R1YDLUZZjSYDX8OF07D6UeUrOa4Issn5GBRsLVjkdzV4cK0XGsLKlKMcKz5QqK3OFFBSlMXwSilfCn5VNWfCMCVGGOEkT5Xy3z8Li5nQ0Tkc6sh9tf/Dr+0SCSx8xDO8F7ohGSY6YGO3GfuM56nGek6jkuJCgkeUkIekMJfBx6gTjr+P5pO/0prZ0/j9ITjAKHic9TxiWpQBuo2gTd40mUg1L19WO0cVq1zQ0FVmmrnXwdmO1TGHLCcMFR2wPN9Zdq3PX0pTOvdZUxh5AHd4NEEMJhguAPwiTikl0AgAA",
"claimed": false,
"claimed_bidders": [],
"highest_bid_amount": 0,
"bin": true,
"bids": []
}
}
I would like to sort the objects from lowest to highest using the "starting_bid" key's value. Is this possible? From my research I heard I had to convert the data to an array to search from it, is there a way to do that (since the JSON object came from an API request). Also, is it possible to make the 'sorting algorithm' into a function? I'm happy to give any info you need.
Edit: Attempted Solutions (so far): Solution 1 (Didn't Work)
function sortByValue(data) {
const sortable = Object.entries(data)
.sort(([, a], [, b]) => a - b)
.reduce((r, [k, v]) => ({ ...r, [k]: v }), {});
}
Solution 2 (Thanks Besufkad Menji) (Worked):
function sortByValue(data) {
data.auctions.sort((a, b)=>a.starting_bid - b.starting_bid);
return data;
}
Array.prototype.sortis something you can look into w3schools.com/js/js_array_sort.asp