我的javascript对象数组就像那样...
$scope.object[]={name:azhar, rating:4},
{name:raheel, rating:1},
{name:faran, rating:5}
如果我打印我的对象数组,我会在控制台中得到类似的输出
0:
Rating:"4.00"
name:"Azhar"
1:
Rating:"1.00"
name:"raheel"
2:
Rating:"5.00"
name:"faran"
在java脚本中,我在我的数组中发送这样的数据。
$scope.object[$scope.arraycount]={name:$scope.array[$scope.arraycount],Rating:$scope.avgRating}
我想在java脚本中对这个数组进行排序,任何人都可以帮助我吗?
答案 0 :(得分:0)
试试这个
let data = [{name:"azhar", rating:4},
{name:"raheel", rating:1},
{name:"faran", rating:5}];
data.sort((a,b) => b.rating - a.rating);
console.log(data);