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

156
Views
issues with localStorage and saving values

I have a program where I have these strings being added to an array. However, there are many strings that are triggered by a certain condition, which can be met multiple times, however I only want it to be added on the first occurrence. So I have implemented a system where the event of adding the string to the array is triggered by the original condition, and a boolean expression. Here is an example of one of those conditions:

if (count >= 10 && displayMulti == true) {
        consoleData.shift()
        consoleData.push("Multi available")
        displayMulti = false
        window.localStorage.setItem("display_multi", String(displayMulti))
        updateConsole()
    }

When the string is added to the array, the boolean, displayMulti, is set to false so that it will not trigger again. However, upon refreshing the page, it will still trigger. I'm not sure why because I feel like I have saving the values to localstorage correctly. Code is below:

if (window.localStorage.getItem("display_multi") != null ) {
    displayMulti = Boolean(window.localStorage.getItem("display_multi"))
} else {
    console.log("here")
    var displayMulti = true
}

There "here" console log statement is not triggered. So I have no idea why this would keep triggering because I don't see how the boolean is true. I've tested at like so many different points I genuinely have no idea what's wrong. I also don't think those values are affected anywhere else in my code. Any help is appreciated.

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

0

Here is a solution that properly parses your string as a boolean. Instead of Boolean(), a conditional (window.localStorage.getItem("display_multi") === 'true')(window.localStorage.getItem("display_multi") === 'true') is used.

if (window.localStorage.getItem("display_multi") != null ) {
    displayMulti = (window.localStorage.getItem("display_multi") === 'true')
} else {
    console.log("here")
    var displayMulti = true
}

if (count >= 10 && displayMulti == true) {
    consoleData.shift()
    consoleData.push("Multi available")
    displayMulti = false
    window.localStorage.setItem("display_multi", String(displayMulti))
    updateConsole()
}
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!