vendredi 11 septembre 2015

How to process data in object collection?

Now, in my object collection,obj:

{date:2015/9/11,name:Ann,apple:1},
{date:2015/9/12,name:Ann,apple:0},
{date:2015/9/13,name:Ann,apple:1},
{date:2015/9/11,name:Bob,apple:1},.....

and I print it out like this:

2015/9/11  Ann     1  
2015/9/12  Ann     0  
2015/9/13  Ann     1  
2015/9/11  Bob     1  
2015/9/12  Bob     1  
2015/9/13  Bob     1  

Here is my code

var index, objLen
for (index = 0, objLen = obj.length; index<objLen; ++index){
    console.log(obj[index].date +'\t'+ obj[index].name +'\t'+ result[index].apple)
}

I wish to output:

2015/9/13  Ann     2  
2015/9/13  Bob     3 

This shows how many apples Ann and Bob have eaten in this three days

I want to know how to get the output.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire