Home > Article > Backend Development > javascript - How to accumulate poll values when the object code values in the array are the same
var arr = [
{"code": "a", "poll": 7},
{"code": "b", "poll": 2},
{"code": "c", "poll": 18},
{"code": "a", "poll": 5},
{"code": "c", "poll": 12},
{"code": "a", "poll": 1}
];
var arr2 = [
{"code": "a", "poll": 13},
{"code": "b", "poll": 2},
{"code": "c", "poll": 30}
];
How to achieve the transformation from arr → to arr1, and the code value is not only a b c, but also adsdsd dsdsd a223, any value. How to achieve a similar transformation
var arr = [
{"code": "a", "poll": 7},
{"code": "b", "poll": 2},
{"code": "c", "poll": 18},
{"code": "a", "poll": 5},
{"code": "c", "poll": 12},
{"code": "a", "poll": 1}
];
var arr2 = [
{"code": "a", "poll": 13},
{"code": "b", "poll": 2},
{"code": "c", "poll": 30}
];
How to realize the transformation from arr → to arr1, and the code value is not only a b c, but also adsdsd dsdsd a223, any value. How to realize a similar transformation