I have referred these questions listed below, but didn't helped me out.
- Counting the occurrences / frequency of array elements
- Count values of the inner two-dimensional array - javascript
- Count elements in a multidimensional array
I want to get count from object with specific value. For example, I have this array list,
var testData = [
{
"issue_type": "Warning",
"created_date": "2019-05-13T13:43:16.437Z",
},
{
"issue_type": "Warning",
"created_date": "2019-05-13T13:45:16.330Z",
},
{
"issue_type": "Alert",
"created_date": "2019-05-13T13:43:16.437Z",
},
{
"issue_type": "Alert",
"created_date": "2019-05-13T13:45:16.330Z",
}
]
I want to count how many objects with key "issue_type"="Warning"
are there.
I tried with this loop but it is not what I'm looking for,
var counts = {};
for (var i = 0; i < arr.length; i++) {
var num = arr[i];
counts[num] = counts[num] ? counts[num] + 1 : 1;
}
console.log(count['issue_type']);
Please suggest me the way out.