I'm using an ajax call to retrieve values from a JSON structure and pushing them into a JavaScript array with .push for each iteration. However, I have multiple instances of the same value (e.g. person's name) in the array and I want to count the number of identical names and remove duplicates.
The ultimate aim is to create a chart displaying each person's name along with how many times they appear in the array.
Here is my current code:
var arr = [];
$.each(data.d.results, function (a, data) {
$.ajax({
url: "http://helpdesk.monjasa.com/IT/_vti_bin/ListData.svc/ITHelpdeskRequests(" + data.RequesterId + ")/CreatedBy",
headers: {
'accept': 'application/json;odata=verbose',
'content-type': 'application/json;odata=verbose'
},
success: function (data2) {
$.ajax({
url: "http://helpdesk.monjasa.com/IT/_vti_bin/ListData.svc/ITHelpdeskRequests(" + data.AssignedToId + ")/AssignedTo",
headers: {
'accept': 'application/json;odata=verbose',
'content-type': 'application/json;odata=verbose'
},
success: function (data3) {
$(".inner").prepend('<p>' + data.Request + ' <br>Submitted by: ' + data2.d.Name + '<br>Assigned to: ' + data3.d.Name + ' | Due in: ' + data.DueInDays + ' day(s)</p>');
arr.push(data3.d.Name);
console.log(arr);
}
});
}
});
Does anyone have any suggestions on how I can accomplish this task?