Here is the JSON data I have:
{
"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"
}
}],
"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"
}
}
If this JSON response is from a web server, is there a possible way to utilize the reduce() method in this scenario?
I attempted the following approach:
$.ajax({
url:"http://...",
type: "GET",
headers:{"application/vnd+json"},
success: function(data){
var result = data.cells.reduce(function(array, object) {
return array.concat(object.type);
}, {});
console.log(result);
}
)};
Is it feasible to apply reduce here? My goal is to implement the reduce function for the provided JSON structure. Do you see any issues with my AJAX implementation?