oliversb Posted June 29, 2014 Share Posted June 29, 2014 How do I create an array defining the range with a pattern like this:[5, 4, 3, 2, 1, 0] This is to define frame data. I want to be able to write something like this arrayValues(5, 0) Thanks Link to comment Share on other sites More sharing options...
lewster32 Posted June 30, 2014 Share Posted June 30, 2014 You could create a function to do this for you:function arrayValues(start, end) { var output = []; if (start > end) { for (var i = start; i >= end; i--) { output.push(i); } } else { for (var j = start; j <= end; j++) { output.push(j); } } return output;} Link to comment Share on other sites More sharing options...
oliversb Posted June 30, 2014 Author Share Posted June 30, 2014 Thanks. I thought there was some built-in function you see but I'l use that. Link to comment Share on other sites More sharing options...
lewster32 Posted June 30, 2014 Share Posted June 30, 2014 No unfortunately not, and seemingly most of the range functions people have posted online don't work in reverse, or do weird things when you use negative numbers - the example above is a little clunky in how it's written, but it handles these outside cases. Link to comment Share on other sites More sharing options...
Recommended Posts