使用仅对象唯一值对数组项进行分组

时间:2019-04-30 12:07:32

标签: jquery json

我的数组是这样的:

var response = [
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-01",
    "VARIABLENAME": "AVG_12MO_LD_MINUTES",
    "VARIABLECONTRIBUTION": 81
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-02",
    "VARIABLENAME": "AVG_12MO_LD_MINUTES",
    "VARIABLECONTRIBUTION": 80
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-03",
    "VARIABLENAME": "AVG_12MO_LD_MINUTES",
    "VARIABLECONTRIBUTION": 43
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-01",
    "VARIABLENAME": "AVG_12MO_LD_REV",
    "VARIABLECONTRIBUTION": 87
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-02",
    "VARIABLENAME": "AVG_12MO_LD_REV",
    "VARIABLECONTRIBUTION": 43
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-03",
    "VARIABLENAME": "AVG_12MO_LD_REV",
    "VARIABLECONTRIBUTION": 84
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-01",
    "VARIABLENAME": "AVG_12MO_MOVIE_BUYS",
    "VARIABLECONTRIBUTION": 54
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-02",
    "VARIABLENAME": "AVG_12MO_MOVIE_BUYS",
    "VARIABLECONTRIBUTION": 58
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-03",
    "VARIABLENAME": "AVG_12MO_MOVIE_BUYS",
    "VARIABLECONTRIBUTION": 75
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-01",
    "VARIABLENAME": "AVG_12MO_PKG_BUYS",
    "VARIABLECONTRIBUTION": 13
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-02",
    "VARIABLENAME": "AVG_12MO_PKG_BUYS",
    "VARIABLECONTRIBUTION": 54
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-03",
    "VARIABLENAME": "AVG_12MO_PKG_BUYS",
    "VARIABLECONTRIBUTION": 45
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-01",
    "VARIABLENAME": "AVG_12MO_PKG_BUYS_STD",
    "VARIABLECONTRIBUTION": 43
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-02",
    "VARIABLENAME": "AVG_12MO_PKG_BUYS_STD",
    "VARIABLECONTRIBUTION": 88
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-03",
    "VARIABLENAME": "AVG_12MO_PKG_BUYS_STD",
    "VARIABLECONTRIBUTION": 76
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-01",
    "VARIABLENAME": "AVG_12MO_PKG_REV",
    "VARIABLECONTRIBUTION": 97
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-02",
    "VARIABLENAME": "AVG_12MO_PKG_REV",
    "VARIABLECONTRIBUTION": 65
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-03",
    "VARIABLENAME": "AVG_12MO_PKG_REV",
    "VARIABLECONTRIBUTION": 82
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-01",
    "VARIABLENAME": "AVG_12MO_PKG_REV_STD",
    "VARIABLECONTRIBUTION": 36
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-02",
    "VARIABLENAME": "AVG_12MO_PKG_REV_STD",
    "VARIABLECONTRIBUTION": 87
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-03",
    "VARIABLENAME": "AVG_12MO_PKG_REV_STD",
    "VARIABLECONTRIBUTION": 54
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-01",
    "VARIABLENAME": "AVG_12MO_PPV_BUYS",
    "VARIABLECONTRIBUTION": 92
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-02",
    "VARIABLENAME": "AVG_12MO_PPV_BUYS",
    "VARIABLECONTRIBUTION": 65
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA",
    "PROCESSDATE": "2019-04-03",
    "VARIABLENAME": "AVG_12MO_PPV_BUYS",
    "VARIABLECONTRIBUTION": 99
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA_NEW",
    "PROCESSDATE": "2019-04-03",
    "VARIABLENAME": "AVG_12MO_PPV_BUYS",
    "VARIABLECONTRIBUTION": 99
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA_NEW_1",
    "PROCESSDATE": "2019-04-03",
    "VARIABLENAME": "AVG_12MO_PPV_BUYS",
    "VARIABLECONTRIBUTION": 99
  },
  {
    "PROCESS_TYPE": "MONTHLYCAR",
    "MODELNAME": "COX_PTB_DATA_NEW_1_11",
    "PROCESSDATE": "2019-04-03",
    "VARIABLENAME": "AVG_12MO_PPV_BUYS",
    "VARIABLECONTRIBUTION": 99
  }
];

我想将其转换为:

responseData = [
  { 

MODELNAME:“ COX_PTB_DATA”,“ VARIABLENAMEANDCONTRIBUTION”:                 [                     {                         “ VARIABLENAME”:“ AVG_12MO_PPV_BUYS”,                         “变量贡献”:[23,54,66]

                },
                {
                    "VARIABLENAME":"AVG_12MO_PKG_REV_STD",
                    "VARIABLECONTRIBUTION":[66,98,15]

                }
            ]
  },
  MODELNAME: "COX_PTB_DATA_NEW",  "VARIABLENAMEANDCONTRIBUTION":
            [
                {
                    "VARIABLENAME":"AVG_12MO_PPV_BUYS",
                    "VARIABLECONTRIBUTION":[28,53,96]

                },
                {
                    "VARIABLENAME":"AVG_12MO_PKG_REV_STD",
                    "VARIABLECONTRIBUTION":[61,18,12]

                }
            ]
         }

]

我尝试使用jquery使用.map,.rduce函数,但无法像这样形成,下面我分享了我的小提琴MY fiddle

有人帮助我。

0 个答案:

没有答案