Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
How to append to an array every minute on every reload of page in Javascript?

I have a HTML code which is taking stock price which is updating every 1 minute ( on reload of page ). I want to make a graph out of the stock price. For this I would want to make an array in the morning and then as and when prices are updated every minute, the array is updated too. How can I do it? I tried to use local storage but just unable to get the desired results.

vwap_ltp_percentage is the variable here which I am getting every minute and which I want to append to an array

    vwap_ltp_array = Array()
    vwap_ltp_array.push(vwap_ltp_percentage)
    console.log(vwap_ltp_array)
    if (localStorage.getItem('test') == null) {
        localStorage.setItem('test',[])
    }
    else {
        localStorage.setItem('test',[])
    }
    localStorage.setItem("test", JSON.stringify(vwap_ltp_array))
    console.log(localStorage)

ge)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In your case, you are always starting with an empty array, the if...else construct is not doing anything... Instead, you need to construct the initial array from the storage if an entry exists there.

    var testString = localStorage.getItem('test');
    vwap_ltp_array = testString ? JSON.parse(testString) : []
    vwap_ltp_array.push(vwap_ltp_percentage)
    localStorage.setItem("test", JSON.stringify(vwap_ltp_array))
    console.log(localStorage)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!