第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

將 JSON 數(shù)據(jù)數(shù)組分組到另一個(gè)數(shù)組

將 JSON 數(shù)據(jù)數(shù)組分組到另一個(gè)數(shù)組

我正在構(gòu)建一個(gè) Angular 7 應(yīng)用程序。在這個(gè)應(yīng)用程序中,我從服務(wù)器獲取 JSON 數(shù)據(jù),然后我想按特定鍵對(duì)其進(jìn)行分組。我設(shè)法做到了這一點(diǎn),但我不再有數(shù)組而是某種對(duì)象。啟動(dòng) JSON 數(shù)據(jù)[{    "id": 67,    "survey_id": 26,    "question_id": 63,    "user_id": 35,    "privacy": null,    "score": null,    "comment": "A nice little comment",    "binary": null,    "reasons": null,    "preferences": "{}",    "created_at_date": "2019-09-18",    "created_at_time": "19:53",    "user": {        "id": 35,        "fullname": "Michael Palin"    },    "can_manage": true},{    "id": 68,    "survey_id": 26,    "question_id": 64,    "user_id": 4,    "privacy": null,    "score": null,    "comment": "Another little comment",    "binary": null,    "reasons": null,    "preferences": "{}",    "created_at_date": "2019-09-18",    "created_at_time": "19:53",    "user": {        "id": 4,        "fullname": "Roland Smacker"    },    "can_manage": true},{    "id": 69,    "survey_id": 26,    "question_id": 65,    "user_id": 4,    "privacy": null,    "score": null,    "comment": "Some more comments",    "binary": null,    "reasons": null,    "preferences": "{}",    "created_at_date": "2019-09-18",    "created_at_time": "19:53",    "user": {        "id": 4,        "fullname": "Roland Smacker"    },    "can_manage": true},}]這是我的分組代碼setupStats() {    const groupBy = (array, key) => {      return array.reduce((result, currentValue) => {        (result[currentValue[key]] = result[currentValue[key]] || []).push(          currentValue        );        return result;      }, {});    };    const grouped = groupBy(this.collection, 'user_id');    console.log(grouped);  }這是輸出{4: Array(3), 35: Array(1)}4 和 35 是 user_ids。我希望他們獲取數(shù)組的一部分,以便我可以循環(huán)它們,而我現(xiàn)在不能這樣做。
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 227 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)