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?
Use iter() and next() to skip first element of a for-loop User iter(object) to return an iterable for any iterable object . Call next(iterator) on iterator as the iterable for object to skip the first element of iterator .
A return statement inside a for-loop, by contrast, would exit the loop and the calling function. To get such drastic behavior from an each-loop, you'd need to set a flag with closure-scope inside the each-loop, then respond to the flag outside it.
Is this good enough?
$.each(data.collection.slice(1), DoStuff);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With