js中对象数组排序

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>数组反转</title>
</head>
<body>
    

    <script>
    var arr = [{cryptocurrencyRank: 16, cryptocurrencyId: "bitconnect", cryptocurrencyEn: "BitConnect", cryptocurrencySymbol: "bcc", costPriceCny: 1000},{cryptocurrencyRank: 1, cryptocurrencyId: "bitcoin", cryptocurrencyEn: "Bitcoin", cryptocurrencyZh: "比特币", cryptocurrencySymbol: "btc"}];
      
        //console.log('未反转',arr)
        // 方法一
        // var a =[]
        // for(var i=0;i<arr.length;i++){
        //    a.unshift(arr[i])
        // }
        // 方法二,按照对象某个属性排序
        function sortBank(a,b){  
        return a.cryptocurrencyRank-b.cryptocurrencyRank
        }
        arr.sort(sortBank);
        console.log('反转1',arr);
    </script>
</body>
</html>
原文地址:https://www.cnblogs.com/lzq035/p/8005811.html