In prototype the cumbersome for:
for (i=0; i<10; i++) { ... }
can be written as
$R(0, 10).each(function(i){ ... });
Is there an equivalent of range in JQuery ?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See http://code.google.com/p/jquery-utils/source/browse/trunk/src/jquery.arrayUtils.js?r=452
jQuery does not provide range expansion natively, but it’s an easy addition. There are only two parts to it. First the range function should return an array with the each item in the range expanded to an array value. Next add a method to
Arrayto iterate each object passing in a handler function.Here we define
forEachthat’s part of the ECMA-262 standard for iterating over arrays. See MDC for more details.Next, we need a function to expand ranges to an array within the jQuery namespace. Taken from the above URL (original source – http://blog.outofhanwell.com/2006/03/29/javascript-range-function/)
:
Alrighty, now we can do:
Or use it with a custom step value instead of 1