E
E
ettaluni2021-06-30 12:30:30
JavaScript
ettaluni, 2021-06-30 12:30:30

One line solution, array of years from given to today?

Good afternoon, you need to get an array of years from a certain given to today. For example, from 2015 - [2015, 2016, 2017, 2018, 2019, 2020, 2021]. And that on IEshke 9 it was supported. JS tricksters help with solution.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vovash, 2021-06-30
@ettaluni

function generateArrayOfYears(year) {
  var max = new Date().getFullYear()
  var years = []

  for (var i = year; i <= max; i++) {
    years.push(i)
  }
  return years
}

console.log(generateArrayOfYears(2015)) // -> [2015, 2016, 2017, 2018, 2019, 2020, 2021]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question