80
rated 0 times
[
87]
[
7]
/ answers: 1 / hits: 54944
/ 15 Years ago, thu, october 15, 2009, 12:00:00
I'm trying to create a dynamic select box in JavaScript with a range of years starting with 'some' year and ending with the current year. Is there anything like Ruby's range class in JavaScript or do I have to loop trough the years using a for loop?
Here's what I've come up with though I think it's a bit much considering in Ruby I can just use a range.
this.years = function(startYear){
startYear = (typeof(startYear) == 'undefined') ? 1980 : startYear
var currentYear = new Date().getFullYear();
var years = []
for(var i=startYear;i<=currentYear;i++){
years.push(i);
}
return years;
}
More From » arrays