0
我有一個JSON對象數組這樣分組概括
var scores= [{sectionid:1,sectiontitle:'Section1',score:5},
{sectionid:1,sectiontitle:'Section1',score:15},
{sectionid:1,sectiontitle:'Section1',score:7},
{sectionid:1,sectiontitle:'Section1',score:4},
{sectionid:2,sectiontitle:'Section2',score:5},
{sectionid:2,sectiontitle:'Section2',score:45},
{sectionid:2,sectiontitle:'Section2',score:13},
{sectionid:3,sectiontitle:'Section3',score:6},
{sectionid:3,sectiontitle:'Section3',score:23},
{sectionid:3,sectiontitle:'Section3',score:9},
{sectionid:3,sectiontitle:'Section3',score:12},
{sectionid:3,sectiontitle:'Section3',score:55},
{sectionid:4,sectiontitle:'Section4',score:4},
{sectionid:4,sectiontitle:'Section4',score:35}];
但我需要得到這些組JSON對象數組與另一個變量分組總分就在裏面。
因此所產生的變量應該是這樣的
var result=[{sectionid:1,sectiontitle:'Section1',score:26},
{sectionid:2,sectiontitle:'Section2',score:63},
{sectionid:3,sectiontitle:'Section3',score:105},
{sectionid:4,sectiontitle:'Section4',score:39}];
我嘗試使用各種功能的穿越得分變量。但發現很複雜。我們如何才能以最好,最快捷的方式使其成爲可能
完美的我的朋友...謝謝! –