Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript对象的排序和排序数组_Typescript_Sorting - Fatal编程技术网

Typescript对象的排序和排序数组

Typescript对象的排序和排序数组,typescript,sorting,Typescript,Sorting,我对angular有点陌生,最近我有一个代码,可以将一个对象数组推到一个新数组中 mainArr.Survey.forEach(item => { newArray.push({ list: item.data.map((option: any) => { const target = this.dataArray.find(x => x.name === item.name && option == x.valu

我对angular有点陌生,最近我有一个代码,可以将一个对象数组推到一个新数组中

mainArr.Survey.forEach(item => {
    newArray.push({
        list: item.data.map((option: any) => {
            const target = this.dataArray.find(x => x.name === item.name && option == x.value);
            return {
                [option]: target ? target.count : 0
            }
        })
    });
});
该输出如下所示:

"list": [
      {
        "1": "37"
      },
      {
        "2": "45"
      },
      {
        "3": "12"
      },
      {
        "4": "21"
      },
      {
        "5": "21"
      }
    ],
是否有一种方法可以代替计数从其他对象值(从高到低)返回其排名?像这样

 "list": [
      {
        "1": "2" //37
      },
      {
        "2": "1" //45
      },
      {
        "3": "4" //12
      },
      {
        "4": "3" //21
      },
      {
        "5": "3" //21
      }
    ],

您的数据结构是什么?它与[list=col1]相同