Home  >  Article  >  Backend Development  >  javascript - How to accumulate poll values ​​when the object code values ​​in the array are the same

javascript - How to accumulate poll values ​​when the object code values ​​in the array are the same

WBOY
WBOYOriginal
2016-10-11 14:23:331242browse

var arr = [

<code>    {"code": "a", "poll": 7},
    {"code": "b", "poll": 2},
    {"code": "c", "poll": 18},
    {"code": "a", "poll": 5},
    {"code": "c", "poll": 12},
    {"code": "a", "poll": 1}
];
</code>

var arr2 = [

<code>{"code": "a", "poll": 13},
{"code": "b", "poll": 2},
{"code": "c", "poll": 30}</code>

];
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

Reply content:

var arr = [

<code>    {"code": "a", "poll": 7},
    {"code": "b", "poll": 2},
    {"code": "c", "poll": 18},
    {"code": "a", "poll": 5},
    {"code": "c", "poll": 12},
    {"code": "a", "poll": 1}
];
</code>

var arr2 = [

<code>{"code": "a", "poll": 13},
{"code": "b", "poll": 2},
{"code": "c", "poll": 30}</code>

];
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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn