Created
May 1, 2017 12:12
-
-
Save asterion/34064cbefb7e55336b42c27f20fdab20 to your computer and use it in GitHub Desktop.
json data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = [ | |
{type: "a", income: 1}, | |
{type: "a", income: 1}, | |
{type: "e", income: 1}, | |
{type: "c", income: 1}, | |
{type: "d", income: 1}, | |
{type: "d", income: 1}, | |
{type: "d", income: 1}, | |
]; | |
var total = {}; | |
for(i=0; i < data.length; i++){ | |
if (total[data[i].type] == undefined) { | |
total[data[i].type] = 0; | |
} | |
total[data[i].type] = total[data[i].type] + data[i].income; | |
} | |
console.log(total.a); | |
console.log(total.c); | |
console.log(total.d); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment