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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:44:29+00:00 2026-05-25T09:44:29+00:00

I’m rewriting a project with hardcoded values to be flexible and dynamic. However, I

  • 0

I’m rewriting a project with hardcoded values to be flexible and dynamic. However, I keep running into trouble.

I wrote most of my JS code now, but I found a couple of bugs that I can’t fix, so I decided to start from scratch. I was now thinking to put my data into an object which keeps track of totals. The project basically lets people order tickets, hotels, etc. per event.

However, this used to be hardcoded, like I said. Now it has to be flexible and I’m not sure if it’s possible to dynamically create an object? Here’s my problem:

The object I used to use was the following:

var total = {   amount: 0,
            tickets: 0,
            passes: 0,
            fri: 0,
            sat: 0,
            sun: 0,
            freecarpass: 0,
            freepass_fri: 0,
            freepass_sat: 0,
            freepass_sun: 0,
            passes_fri: 0,
            passes_sat: 0,
            passes_sun: 0,
            passes_totalPurchase: 0
        };

As you can see, the days are hardcoded. However, with the new system, every event will have different days, so I need to be able to build my object based on that, if that makes sense.

For example, if the event runs from wednesday till saturday, the days in the object would be:

wed: 0, thu: 0, fri: 0, sat: 0 

etc.

I’m not sure how to achieve this, if this is even possible? I can provide more code of the project if needed. Thanks in advance.

  • 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-25T09:44:30+00:00Added an answer on May 25, 2026 at 9:44 am

    While I’m not convinced this is the best way to go about solving your problem, yes you can add or remove properties of an object at whim in Javascript. Essentially JS objects are just key-value pairs of properties. So you could start by having an object that all days will share, something like this:

    var total = {  
        amount: 0,
        tickets: 0,
        passes: 0
    };
    

    Then you can add a property simply by assigning it a value, such as:

    total.sat = 3;
    total.sun = 1;
    

    W3Schools has a longer explanation of this here.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.