Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8556421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:20:48+00:00 2026-06-11T15:20:48+00:00

I have a years range stored into two variables. I want to create an

  • 0

I have a years range stored into two variables. I want to create an array of the years in the range.

something like:

var yearStart = 2000;
var yearEnd = 2040;

var arr = [];

for (var i = yearStart; i < yearEnd; i++) {

     var obj = {
        ... 
     };

      arr.push(obj);
}

What should I put inside the obj ?

The array I’d like to generate would be like:

arr = [2000, 2001, 2003, ... 2039, 2040]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:20:50+00:00Added an answer on June 11, 2026 at 3:20 pm

    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++);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the following example I have two years worth of data denoted by data_2007
I have tables named: Posts_August_2011 Posts_September_2011 Posts_October_2011 Posts_November_2011 Posts_December_2011 Posts_January_2012 I want to create
If i would like to have an age range in my search form. From:
I have a large set of data for a range of product from two
I have an obejct of the form: var test = {2011:{10:4,9:9,8:15,7:11,6:11,5:13,4:9,3:5,2:9,1:4,0:20},2010:{11:9,10:23,9:58}} I want to
We have 3 years old solution (.sln) with about 20 projects (.csproj). It is
I have 5 years of work experience in developing WEB and WIN application using
I have 4 years experience on DotNet, not much. I now learned developing for
I have 100 years of monthly data where each month is a file and
I am not a developer, but I have spent years testing and managing software

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.