Would anyone know how to filter out repeated data from an array of objects? I have a simple parent and child list. The child list has a field with the parent's ID.
Here is an exmaple of what my child data looks like:
responseText: {
d: {
results: [{
ID_of_parent: "17",
Day_or_night: "day",
Start: "2016-06-01 08:00",
End: "2016-06-01 10:00",
Hours: "2"
}, {
ID_of_parent: "17",
Day_or_night: "day",
Start: "2016-06-01 13:00",
End: "2016-06-01 14:00",
Hours: "1"
}, {
ID_of_parent: "17",
Day_or_night: "night",
Start: "2016-06-01 21:00",
End: "2016-06-01 22:00",
Hours: "1"
}, {
ID_of_parent: "22",
Day_or_night: "day",
Start: "2016-06-01 09:00",
End: "2016-06-01 10:00",
Hours: "1"
}, {
ID_of_parent: "22",
Day_or_night: "day",
Start: "2016-06-01 14:00",
End: "2016-06-01 15:00",
Hours: "1"
}, {
ID_of_parent: "54",
Day_or_night: "day",
Start: "2016-06-01 13:30",
End: "2016-06-01 16:00",
Hours: "2.5"
}]
}
}
And here is the parent data:
responseText: {
d: {
results: [{
ID: "17",
description: "Description 1"
}, {
ID: "22",
description: "Description 2"
}, {
ID: "34",
description: "Description 3"
}, {
ID: "54",
description: "Description 4"
}]
}
}
What im simply trying to accomplish is to get the child lists data via ajax then foreach, remove the duplicate IDs and then get me the parent ID. At the moment this is what I have so far:
$.ajax({
url:"Child_list_path",
dataType: "json",
cache: false,
success: function (child) {
$.each(child.d.results, function (index, children) {
$.ajax({
url: parent_list_path("+children.Incident_ID+")",//filter by ID
dataType : 'json',
cache : false,
success : function (parent) {
//stuff
}
});//end of inner ajax
});//end of each
}//sucess end
});
Problem with this is that that in the child data, there can be multiple entries that have the same parent's ID. So what happens during the for each sequence is that it will pull the filtered parent data multiple times for the same ID when I just need to get the data for each unique IDs.
EDIT: My objective is to be able to filter repeated ID_of_parent in the child data. So instead of looping trough 17,17,17,22,22,54 I just want it to loop trough 17,22,54.