Okay so i am trying to sort through some results i hold in either a Javascript Object or Javascript Array of Objects, but i cant seem be able to crack this one, however i would like to be able to sort by the different key's values..
What i tried (With the key "amount")
(Imagine the sortable variable holds either the Javascript Object or Javascript Array of Objects)
var sortable;
sortable.sort(function (a, b) {
return a.amount > b.amount;
});
console.log(sortable);
Javascript Object
"1": {
"BTC": {
"name": "Bitcoin",
"symbol": "BTC",
"amount": "5.0000000000",
"rank": "1",
"usd_coin": "3580.68",
"btc_coin": "1.00",
"volume": "1324380000.00",
"marketcap": "59337865239.00",
"1h": "1.62",
"24h": "0.65",
"7d": "-12.23"
},
"ETH": {
"name": "Ethereum",
"symbol": "ETH",
"amount": "1153.0000000000",
"rank": "2",
"usd_coin": "247.05",
"btc_coin": "0.07",
"volume": "421132000.00",
"marketcap": "23388713395.00",
"1h": "2.06",
"24h": "1.70",
"7d": "-12.80"
},
"LTC": {
"name": "Litecoin",
"symbol": "LTC",
"amount": "15.0000000000",
"rank": "5",
"usd_coin": "48.84",
"btc_coin": "0.01",
"volume": "276411000.00",
"marketcap": "2587009816.00",
"1h": "2.90",
"24h": "1.84",
"7d": "-20.80"
}
}
Array of Objects
[
[
{
"name": "Bitcoin",
"symbol": "BTC",
"amount": "5.0000000000",
"rank": "1",
"usd_coin": "3580.68",
"btc_coin": "1.00",
"volume": "1324380000.00",
"marketcap": "59337865239.00",
"1h": "1.62",
"24h": "0.65",
"7d": "-12.23"
}
],
[
{
"name": "Ethereum",
"symbol": "ETH",
"amount": "1153.0000000000",
"rank": "2",
"usd_coin": "247.05",
"btc_coin": "0.07",
"volume": "421132000.00",
"marketcap": "23388713395.00",
"1h": "2.06",
"24h": "1.70",
"7d": "-12.80"
}
],
[
{
"name": "Litecoin",
"symbol": "LTC",
"amount": "15.0000000000",
"rank": "5",
"usd_coin": "48.84",
"btc_coin": "0.01",
"volume": "276411000.00",
"marketcap": "2587009816.00",
"1h": "2.90",
"24h": "1.84",
"7d": "-20.80"
}
]
]