KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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; }
Tags (comma-separated)
Save Edits
Cancel