even shorter if you can lose the yearStart value:
var yearStart = 2000;
var yearEnd = 2040;
var arr = [];
while(yearStart < yearEnd+1){
arr.push(yearStart++);
}
UPDATE:
If you can use the ES6 syntax you can do it the way proposed here:
let yearStart = 2000;
let yearEnd = 2040;
let years = Array(yearEnd-yearStart+1)
.fill()
.map(() => yearStart++);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…