Currently, I am facing a challenge with a recursive type of function that dynamically runs based on a returned query. My goal is to prevent duplicate or redundant data in my array during each recursive loop by filtering out any duplicates.
Here is the code snippet in question:
function getbarxAxis() {
$.ajax({
url: siteurl+"patients_report/bardata_date",
type: "POST",
dataType: "JSON",
success: function(data) {
var categories = new Array();
for (var i in data) {
categories.push(data[i]["datemonths"]);
getbarseries(data[i]["datemonths"]);
}
}
});
}
This is the initial ajax call fetching all the datemonths. If, for instance, two datemonths are obtained, the function inside becomes recursive. Within this recursive function - getbarseries, there is an array storing the retrieved data:
function getbarseries(month) {
$.ajax({
url: siteurl+"patients_report/bardataclinic/"+month,
type: "POST",
dataType: "JSON",
success: function(data) {
var names = new Array();
for(var i in data) {
names.push(data[i]['clinic_name']);
}
alert(JSON.stringify(uniqueNames));
}
});
}
The first recursion's data might look something like this:
Clinic 1, Clinic 2, Clinic 3, Clinic 4
And the second recursion's data could be:
Clinic 1, Clinic 2, Clinic 3, Clinic 4, Clinic 5
To ensure cleaner results and eliminate duplicates, I am seeking a solution that will identify and exclude any duplicate entries from the array. The desired output after two recursions should resemble this:
Clinic 1, Clinic 2, Clinic 3, Clinic 4, Clinic 5