Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I skip the first iteration of an $.each()?

Tags:

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?

like image 498
mwjackson Avatar asked Sep 08 '09 22:09

mwjackson


People also ask

How do you skip the first row in a list in Python?

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 .

How do I get out of for each loop?

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.


1 Answers

Is this good enough?

$.each(data.collection.slice(1), DoStuff); 
like image 96
Tomas Aschan Avatar answered Sep 29 '22 13:09

Tomas Aschan