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

  • Home
  • SEARCH
  • 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 8444989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:32:32+00:00 2026-06-10T09:32:32+00:00

I have a function that pushes a dynamic amount of numbers into an array

  • 0

I have a function that pushes a dynamic amount of numbers into an array when I click a button, the code looks like this:

$('#calculate').click(function(e) {

var foo = $(".foo"),
    A = [],
    B = [];

    //Push values
foo.each(function(){
  var $t = $(this),
    num = $t.val(),
    xnum = num * 2.42;
  A.push(xnum);
  B.push(num);
});

//more stuff down here... 
//.ajax() to run and print a calculation

I’m getting these values from <select> menus and then I have a button that removes the <select> menu that it accompanies using the .empty() function…

I run into a problem when I calculate, THEN delete one of the <select> menus and recalculate… The value from the deleted <select> is still included in my calculation!

I figured the easiest way to reset the array would be to use:

A.length = 0;
B.length = 0;

But for some reason these aren’t reseting the arrays and the old values are still included in the new calculation…

Is there a better way I can totally clear the array before I start pushing items into it?

  • 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-10T09:32:34+00:00Added an answer on June 10, 2026 at 9:32 am

    Try this

    $(document).on("click", "#remove", function() {
        $this=$(this);
        $this.parent('.foowrap').fadeOut(function() {
            $this.parent('.foowrap').empty();
        });
    });
    

    Update: Use class .remove instead of id #remove, id meant to be unique.

    DEMO.

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

Sidebar

Related Questions

I have a little bit of code that looks just like this: function StrippedExample(i1,
I have the following code that pushes check-box values to an array. I want
In my Java code I have function that gets file from the client in
I have function Start() that is fired on ready. When I click on .ExampleClick
I have a function that counts the amount of visits a page has, and
I have a function void AddEntity(Entity* addtolist) that pushes elements back onto a vector
I have some coding and already pushed this into a variable. I would like
I have function in C++ that takes a vector and pushes some items onto
I have a an array that has 3 values. After the user pushes the
Inside my Controller i have function that runs after user clicks on item, which

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.