如何对数组进行排序并为每个数组分配一个值。将每个值从最低到最高排序

时间:2019-05-24 00:58:40

标签: javascript arrays sorting object

我有一系列的分数。我正在尝试基于 从最高到最低,然后为数组中的每个项目分配一个等级。 最高的值将具有最高的等级。例如 在=====

之前
var obj1 = [ {
category:"pink",
score1:300,
score2:35,
score3:40,
score4:60,
category:"black",
score1:30,
score2:10,
score3:20,
score4:40,
score5:50
}]

之后:====

[{
category:"Pink",
score1:5,
score2:1,
score3:2,
score4:4,
score5:3
},{
category:"black",
score:3,
score2:1,
score3:2,
score4:4,
score5:5
}]

得分1在粉红色方面得分最高。 得分5代表黑人最高。

var obj1 = [ {
category:"pink",
score:300,
score2:35,
score3:40,
score4:60,
score5:52
},{
category:"Pink",
score:50,
score2:10,
score3:20,
score4:40,
score5:30
}]

var keys = Object.values(obj1[1]);
keys.shift();
console.log(keys)

var obj1 = [ {
category:"pink",
source1:300,
source2:35,
source3:40,
source4:60,
source5:52
},{



category:"Pink",
source1:50,
source2:10,
source3:20,
source4:40,
source5:30




}]









var keys = Object.values(obj1[1]);
keys.shift();
console.log(keys)

0 个答案:

没有答案