my json array store looks like this
[{
"role": "Executive Director",
"name": "David Z",
...},
{
"role": "Executive Director",
"name": "David Z",
...},
{
"role": "Non Executive Chairman",
"name": "Hersh M",
...},
{
"role": "Non Executive Director",
"name": "Alex C",
...},
{
"role": "Company Secretary",
"name": "Norman G",
...}]
from this array comes a few html tables.
I loop through store to a draw html table as part of an ajax success function, like this
var table = '';
table += '<tr><td......</td>';
$.each(store, function(i, data) {
// draw row...
// draw row etc...
});
table += '</tr></tbody>';
$("#table_d").append(table);
however for one of the tables I want to skip the 2nd occurrence of David Z (or whatever name that occurs more than once)
var table = '';
table += '<tr><td......</td>';
$.each(store, function(i, data) {
if (i > 0, store[i].name != store[i-1].name) {
// draw row...
// draw row etc...
}
});
table += '</tr></tbody>';
$("#table_d").append(table);
the array will always be ordered so I can compare store[i].name against store[i-1].name for a duplicate name.
so how can I correctly express if store[i].name != store[i-1].name run loop?
If I understand your question correctly, I think you just need to do this