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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:32:43+00:00 2026-06-04T02:32:43+00:00

How to when click Create button add last state of object to array and

  • 0

How to when click “Create” button add last state of object to array and create new clean ready to continue, and if click “Continue” button modyfy only actual object, now is modified all objects in sections array?

Illustrative materials:

HTML:

<button onclick="create()">Create</button>
<button onclick="add()">Continue</button>

​
JavaScript:

var sections = [];

create = function() {
    sections.push(section);

    section.array = [];
    section.c = 0;

    section.add();

    $("body").append("<br>Add to array at moment last state of object and make new one<br>" + JSON.stringify(sections) + "<br >");
}

add = function() {
    section.add();

    $("body").append("<br>continue only this object<br>" + JSON.stringify(sections) + "<br >");
}

var section = {
    array: [],
    c: 0,
    add: function() {
        section.c++;
        section.array.push(section.c);
    }
}​
  • 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-04T02:32:45+00:00Added an answer on June 4, 2026 at 2:32 am

    You will need to create new section objects, instead of resetting the properties of your one section variable (in your create function):

    var sections = [],
    section = makeSection();
    
    function create() {
        sections.push(section); // add the current section
        section = makeSection(); // make a new one
        section.add();
    
        $("body").append("<br>Add to array at moment last state of object and make new one<br>" + JSON.stringify(sections) + "<br >");
    }
    
    function add() {
        section.add();
        $("body").append("<br>continue only this object<br>" + JSON.stringify(sections) + "<br >");
    }
    
    function makeSection() {
        return {
            array: [],
            c: 0,
            add: function() {
                section.c++;
                section.array.push(section.c);
            }
        }​;
    }
    

    Yet, I’d say this is a case for a constructor function:

    function Section() {
        this.array = [];
        this.c = 0;
        // maybe do this automatically on constructing:
        // this.add();
        // sections.push(this);
    }
    Section.prototype.add = function() {
        this.c++;
        this.array.push(section.c);
    }
    

    and then use new Section() instead of makeSection().

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

Sidebar

Related Questions

I want to create a button that has a jQuery click on the fly.
I want to create a button in one of my programs. When they click
I want to create a Toolbar in my application. If you click a button
i have created Array of Linkbutton and when user click on link button it
Is this a bug? When I click 'Create New Action Type' on the Open
I create dynamic LinkButton and I add LinkButton's Click Trigger to UpdatePanel. Now, When
I am using jCarousel. I created a button New Posts, when the user click
How can I create a dynamic button with a click event with JavaScript? I
I have created a button. So when I click the button it gives me
I created a Search Interface in Android. when we click on hardware search button

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.