JavaScript按照对象的某个属性进行排序


	JavaScript按照对象的某个属性进行排序
[编程语言教程]

参考:https://blog.csdn.net/giser_whu/article/details/51485635

CompanyIndex({ _with: ‘location‘ })
        .then((res) => {
          if (res.data && res.success) {
            // this.companyList = res.data
            const companyList1 = res.data
            function sortBy(obj1, obj2) {
              const val1 = obj1.offline_reader_count
              const val2 = obj2.offline_reader_count
              if (val1 < val2) {
                return 1
              } else if (val1 > val2) {
                return -1
              } else {
                return 0
              }
            }
            this.companyList = companyList1.sort(sortBy)
            // this.companyList = res.data
            setTimeout(() => {
              this.loading = false
            }, 600)
          }
        })
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » JavaScript按照对象的某个属性进行排序