I have a JSON list that I want to iterate over, but skip the first entry, like thus:
$.each(
data.collection,
function() { DoStuffButOnlyIfNotTheFirstOne(); }
);
Any ideas?
I have a JSON list that I want to iterate over, but skip the first entry, like thus:
$.each(
data.collection,
function() { DoStuffButOnlyIfNotTheFirstOne(); }
);
Any ideas?
Is this good enough?
$.each(
data.collection,
function(i) {
if (i > 0)
DoStuff();
}
);
$.each(
data.collection,
function(i) { if (i>0) DoStuffButOnlyIfNotTheFirstOne(); }
);
$.each(
data.collection,
function(i) {
if(i)
DoStuffButOnlyIfNotTheFirstOne();
}
);
or, probably more efficiently:
$.each(
data.collection.slice(1),
function() {
DoStuff();
}
);
You can use the good old firstFlag approach:
var firstFlag = true;
$.each(
data.collection,
function() {
if(!firstFlag) DoStuffButOnlyIfNotTheFirstOne();
firstFlag = false;
}
But instead, I'd recommend that you filter your data collection first to remove the first item using a selector.