I am trying to add data to a table, but one of my results is appearing twice. Here is the JSON response I received:
groupname […]
0 {…}
survey_id 2
group_name DEMO
1 {…}
survey_id 1
group_name TEST
This is what my AJAX success function looks like:
if(data){
var txt = "";
for(var i=0;i<=Object.keys(data).length;i++){
if(data ){
txt += '<tr><td>'+data.groupname[i].group_name+'</td></tr>';
}
if(txt != ""){
$("#table").append(txt);
}
}
}
However, when displayed, it shows duplicate entries as seen in the following image: https://i.stack.imgur.com/sMyQc.png
I am looking to display only one DEMO and one TEST entry.