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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:25:17+00:00 2026-05-15T11:25:17+00:00

I am looking to create a set of dynamically created arrays stored inside an

  • 0

I am looking to create a set of dynamically created arrays stored inside an object. the outcome would be something similar to this…

object.array0.length = 5, object.array1.length = 4, etc

the name of the array would be generated from within a for loop based on a numerical value declared elsewhere in the application.

Here is the code that I have…

var obj = {};
var weekNum = 4;

for(i=0; i < weekNum.length;i++) {
    obj['week'+i] = [];
    obj['week'+i].push(day);

    console.log('days stored in week0: '+obj.week0.length);
}

What seems to be happening is that obj['week'+i] doesn’t realize that it is an array, and the push command doesn’t seem to be enough to make it think so. So as a resulting value of obj.week0.length is always 1 with the actual value just being replaced each time as opposed to the array being incremented.

Also fyi,
The parameter day in the above code would be passed in from another function representing any chosen day (Mon, Tues, etc)… However, the sequence and the amount of days passed in could differ but will never exceed 5 (m-f).

  • 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-05-15T11:25:18+00:00Added an answer on May 15, 2026 at 11:25 am

    Looks like a logic problem to me. You’re always only inserting 1 day into the array unless day represents something else altogether.

    var obj = {};
    var weekNum = 4;
    
    // var was missing :)
    for(var i = 0; i < weekNum.length; i++) {
        // check if entry exists before creating new.
        obj['week'+i] = obj['week'+i] || [];
        // you're always only inserting 1 value inside the week array
        // don't you want to loop through the number of days
        // and insert a day entry for *this* week for each day. like this?
        // days is another array of, hmm.. days
        for(var j = 0; j <days.length; j++) {
            obj['week'+i].push(days[j]);
        }
    
        console.log('days stored in week0: '+obj.week0.length);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking to create a user/server control that will be created with something
I'm looking for as simple way to create an identity set. I just want
Im looking to create a control that would look like comic baloon. In WPF
I am looking to create a vertically scrolling website. I'll have a set of
I'm looking for a solution where I have to create a set of records
I am looking to create a query similar to the below using the Zend
I'm looking to create a web between a set of points where the data
I am looking to create a very simple Android platform game. For this, I
Ok I have a dynamically created set of elements where each particular kind gets
I'm having trouble looping through a set of dynamically created UITextFields and storing those

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.