0

How can I compare primaryCurrencyAmount in the array and return the highest numbers to lowest?

const cryptoCoin = [
  {name: 'BTC', amount: 1.4, primaryCurrencyAmount: 1233},
  {name: 'ETH', amount: 10.3, primaryCurrencyAmount: 8000},
  {name: 'USDT', amount: 5, primaryCurrencyAmount: 5125},
  {name: 'LTC', amount: 7, primaryCurrencyAmount: 1400},
];

1 Answers1

0

You can just sort based on primaryCurrencyAmount

cryptoCoin.sort((a,b)=>  b.primaryCurrencyAmount - a.primaryCurrencyAmount)