I want to loop through a json object and count elements with the same value in different arrays. Here's a sample of my object
var testconn =
{"_total": 3,
"values":
[
{
"articlesRead": [
{ "articleId": 1001 },
{ "articleId": 1002 },
{ "articleId": 1003 },
{ "articleId": 1004 },
{ "articleId": 1005 },
{ "articleId": 1006 }
]
},
{
"articlesRead": [
{ "articleId": 1001 },
{ "articleId": 1002 },
{ "articleId": 2001 },
{ "articleId": 2002 },
{ "articleId": 2003 },
{ "articleId": 2004 }
]
},
{
"articlesRead": [
{ "articleId": 1001 },
{ "articleId": 3001 },
{ "articleId": 3002 },
{ "articleId": 3003 },
{ "articleId": 3004 },
{ "articleId": 3005 }
]
}
]
}
I want to count how many the ID's exsist in the array. So for this example I shoud have: 1001 x 3 1002 x 2 1003 x 1 1004 x 1 2001 x 1 etc
I'm looping through my object like this
for (i = 0; i < testconn.values.length; i++) {
var c = testconn.values[i];
for (j = 0; j < c.articlesRead.length; j++) {
var a = c.articlesRead[j];
for (var key in a) {
if (a[key] is bigger then 1) {
count a[key]
}
return number of
}
}
}