{
result: 'OK',
data: [
{ id: '10', categoryid: '3' },
{ id: '85', categoryid: '0' },
{ id: '46', categoryid: '5' },
{ id: '38', categoryid: '5' },
{ id: '59', categoryid: '5' },
{ id: '43', categoryid: '5' },
{ id: '56', categoryid: '0' },
// ...
],
}
const checkItem = item => item.categoryid === '3';const count = response.data.filter(checkItem).length;
// или
const count = response.data.reduce((acc, n) => acc + checkItem(n), 0);
// или
let count = 0;
for (const n of response.data) {
count += checkItem(n);
}
// или
const count = +eval(response.data.map(checkItem).join('+')) || 0;
// или
const count = (function sum(i, n = response.data[i]) {
return n ? checkItem(n) + sum(i + 1) : 0;
})(0);