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

WBOY
Release: 2016-10-11 14:23:33
Original
1242 people have browsed it

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>
Copy after login
Copy after login

var arr2 = [

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

];
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>
Copy after login
Copy after login

var arr2 = [

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

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template