a = (2000..Date.today.year).to_a
In Ruby, above expression returns [2000, 2001, ...snip..., 2018]
I would like to know equivalent JavaScript code.
a = Array.from({length: new Date().getFullYear() - 2000 + 1}, (_, i) => i + 2000)
This can be an answer, but I'm looking for better code in terms of
- Wider browser support without polyfill than above code
- Shorter code like specifing start and end as Ruby's one (My JS example is ugly since I wrote
2000
twice).
A code which satisfies either one is helpful.
EDIT
I would like to use value a
in Vue.js's v-for loop in inline manner like
<option v-for="year in a" :value="year">FY{{year}}</option>
So single expression is desirable.