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 8347767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:28:10+00:00 2026-06-09T07:28:10+00:00

I need to create javascript objects that base on user defined number. So if

  • 0

I need to create javascript objects that base on user defined number. So if user defines 20, then I need to create 20 variables.

var interval_1=0, interval_2=0, interval_3=0, interval_4=0, interval_5=0... interval_20=0;

how do I do it so the name of the object can be dynamically created?

for (i=0; i<=interval; i++){
    var interval_ + i.toString() = i;
}
  • 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-09T07:28:12+00:00Added an answer on June 9, 2026 at 7:28 am

    Use an array:

    var i, count, interval = [];
    
    // user defines count, 20 for example
    count = 20;
    
    for (i = 0; i < count; i++) {
        interval.push(i);
    }
    
    // interval[0] === 0
    // interval[19] === 19
    // interval.length === 20
    

    Note, this starts the index at 0 and goes up to count – 1. Do not use i <= count unless you start i at 1.

    Here is a jsFiddle to illustrate. Hit F12 to open dev tools in most browsers and look at console, or change console.log() to alert().

    Link: http://jsfiddle.net/willslab/CapBN/1/

    Alternatively, you could setup a single object with properties for each value:

    var i, count, intervals = {};
    
    count = 20;
    
    for (i = 0; i < count; i++) {
        intervals["interval_" + i] = i;
    }
    
    //intervals.interval_0 === 0
    //intervals.interval_19 === 19)
    

    Link: http://jsfiddle.net/willslab/EBjx7/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a javascript function that checks if it has been a
Hi I need to create a load of variables in a javascript loop so
I have a situation, where I need to create a new JavaScript object that
I often have the need to search a javascript array that contains objects. I
I need to temporarily track the state of 5 objects in JavaScript. Each of
I am in need of an abstraction for tables in a JavaScript application that
I see a lot of code in some popular Javascript libraries that often create
I need to transfer JavaScript Objects through JSON and transfer it's functions as well.
I am fairly new to JavaScript and I want to create objects and arrays
I need to make a Javascript object that would behave as an associative array,

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.