Например, вы можете использовать reduce()
для вычисления количества объектов данных, где type:"articles"
const response = {
"meta": {
"totalPages": 13
},
"data": [{
"type": "articles",
"id": "3",
"attributes": {
"title": "AAAAA",
"body": "BBBB",
"created": "2011-06-22T14:56:29.00z",
"updated": "2011-06-22T14:56:28.00z"
}
},{
"type": "articles",
"id": "6",
"attributes": {
"title": "AAAAA",
"body": "BBBB",
"created": "2011-06-22T14:56:29.00z",
"updated": "2011-06-22T14:56:28.00z"
}
},
{
"type": "articles",
"id": "10",
"attributes": {
"title": "AAAAA",
"body": "BBBB",
"created": "2011-06-22T14:56:29.00z",
"updated": "2011-06-22T14:56:28.00z"
}
}],
"links": {
"self": "http://example.com/articles?page[number]=3&page[size]=1",
"first": "http://example.com/articles?page[number]=1&page[size]=1",
"prev": "http://example.com/articles?page[number]=2&page[size]=1",
"next": "http://example.com/articles?page[number]=4&page[size]=1",
"last": "http://example.com/articles?page[number]=1&page[size]=1"
}
}
const totalArticles = response.data.reduce((count, val)=>{
if(val.type === 'articles') count++
return count;
}, 0)
console.log(`Total no. of articles : ${totalArticles}`); // Total no. of articles : 3