Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to iterate .each loop one recursion less

Tags:

jquery

I have an .each loop in jQuery.

I want to iterate the loop one time less. i.e if 4 elements are found matching, than the loop should iterate only 3 times.

PS: Not using var i and i++ etc. But actually looping 1 less.

like image 237
umesh moghariya Avatar asked Jul 27 '26 06:07

umesh moghariya


1 Answers

Use the .slice( <start>, <end> ) method (negative end = offset relative to the end):

$(some_object).slice(0, -1).each( ... );
like image 92
Rob W Avatar answered Jul 29 '26 20:07

Rob W



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!