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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:44:50+00:00 2026-06-16T23:44:50+00:00

I want to save and add on every click data to an array. I

  • 0

I want to save and add on every click data to an array. I tried this

var data = [];
var save = [];
s=0;
i=0;

some called function(){
  data[i++] = some result;
  data[i++] = some other result;
}

$('#someelement').click(function(){
save[s++] = data;
console.log(save); // for debugging
i = 0;
data = '';
});

The first save works, but after that I just empty arrays added. Any pointers ?

  • 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-16T23:44:51+00:00Added an answer on June 16, 2026 at 11:44 pm

    It’s because you’re replacing the Array with a string.

    data = '';
    

    You should replace it with a new Array instead.

    data = [];
    

    Or reuse the data Array by adding a shallow copy of data to save, then clearing data.

    save[s++] = data.slice();
    
    data.length = i = 0;
    

    This allows any other code that has a reference to data to retain its reference so that it is always viewing the data that is being updated.

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

Sidebar

Related Questions

Every mintute I want to save some data incase of shutting down. the data
i m working classifieds controller this is code public function create_add(){ if(!empty($this->data)) { if($this->Classified->save($this->data)){
I want to save and load my xml data using XmlReader. But I don't
I want to make an app that allows users to add other users to
i tried the code below!!every time it replaces contents from file textfile.txt i want
I have a problem with my form,i have this error every time i want
This might be easy but I've searched SO and tried some suggestions for this
I want to save every page of a Word Document as text File. I
This is how I save my mutable array actually. [myMutableArray writeToFile:@/Users/myUserIdentifier/Desktop/results.plist atomically:YES]; The array
I have three buttons and need to save some data. I have a idea,

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.