How to Use Local Storage in JavaScript

Поделиться
HTML-код
  • Опубликовано: 4 окт 2024

Комментарии • 221

  • @dcode-software
    @dcode-software  5 лет назад +11

    Check out my similar video on Session Storage:
    ruclips.net/video/RxUc6ZWwgfw/видео.html

  • @guardian962
    @guardian962 2 года назад +16

    I've been struggling with JS & localStorage for MONTHS. This video really helped me understand the basics in a way no one else has. Thank you so much! Definitely going to share this with anyone else struggling

  • @luciusrex
    @luciusrex 6 лет назад +46

    I google for a web dev concept, i find dcode, i click and watch. Once again, concise and with examples all in plain js, excellent work! Keep it up!

  • @farhanyousaf5616
    @farhanyousaf5616 5 лет назад +6

    I love the simplicity and approach of demonstrating it.

    • @dcode-software
      @dcode-software  5 лет назад

      No worries mate 😁

    • @farhanyousaf5616
      @farhanyousaf5616 5 лет назад

      @@dcode-software You should do a more esoteric video on Server Side Events as an intro. And for fuller examples for the ral world, heck make it a course! I'd pay for it =) Have you played with Go?

  • @judaspriest33715
    @judaspriest33715 5 лет назад +4

    Cleanest explanations on youtube hands down!

  • @arshiasaleem5005
    @arshiasaleem5005 4 года назад +5

    Amazing tutorial. You made it so much easy and simplified. Thanks man. Keep up the good work.

  • @MrPurpledin0
    @MrPurpledin0 6 лет назад +12

    Thank you. The most useful tutorial i could find. you're good at this

  • @DubZenStep
    @DubZenStep 3 года назад +7

    For those who are getting the innerHtml error: watch carefully here 10:32.
    You are getting "null" because you probably set "lsOutput" as a class instead of an id of the div.
    If you want to use classes instead of id's, you can use "const lsOutput = document.querySelector(".lsOutput");"

    • @YawiKey
      @YawiKey 10 месяцев назад

      Two hours searching for this on StackOverflow and no answers, thank you 🙏

  • @ulaganathanmahadevan6254
    @ulaganathanmahadevan6254 5 лет назад +5

    Simple and awesome demo! Easy to follow and very useful. Thank you!

  • @kshitizshah6685
    @kshitizshah6685 3 года назад +1

    I am getting goose bumps from this channel.. Thanks a lot you teach extreamely good.. the best programming channel and u are great teacher. Sir please keep on uploading web-development lessons.. !!Love from nepal... BIG FAN

  • @vincenttok
    @vincenttok 3 года назад

    thank you dcode for making this video. it's really help to undestand more about local storage and how to use it using Javascript and your explanation is easy to understand for newbie like me who learnt to program for very first time so thank you again and have a nice day

  • @samuelrajh9755
    @samuelrajh9755 3 года назад +4

    can you make a video on how to store checkbox checked even after refreshing the page in local storage please ?

    • @AdrianaStAubyn
      @AdrianaStAubyn 3 года назад

      have you found out how to do that? if so help a sister out haha

    • @paulhorowitz3340
      @paulhorowitz3340 3 года назад

      @@samuelrajh9755 She asked you if you have found the answer yet. And if you have found the answer, could you please share with her.

    • @samuelrajh9755
      @samuelrajh9755 3 года назад

      @@paulhorowitz3340 oh thanks

    • @samuelrajh9755
      @samuelrajh9755 3 года назад +2

      @@AdrianaStAubyn $(function(){
      $('[type="checkbox"]').each(function () {
      var $this = $(this),
      name = $this.attr('name');
      $this.prop('checked', localStorage[name] === 'true');
      });
      });
      $('[type="checkbox"]').on('change', function() {
      var $this = $(this),
      name = $this.attr('name');
      localStorage[name] = $this.is(':checked');
      });
      $('input').on('change', function() {
      localStorage.input = $(this).is(':checked');
      console.log($(this).is(':checked'));
      });

  • @nguyendat4275
    @nguyendat4275 3 года назад

    The best teacher on youtube, respect!

  • @draganvidakovic4140
    @draganvidakovic4140 Год назад

    Very good video about Local Storage. Clear and Direct.

  • @bimalakamani7001
    @bimalakamani7001 3 года назад +1

    I was looking for this video for months I got finally thank you very much

  • @chrissythompkin2089
    @chrissythompkin2089 6 лет назад +12

    Great tutorial, you're a natural!

  • @sdwhitesox8039
    @sdwhitesox8039 5 лет назад +3

    Good, clear explanation. Could you please do a tutorial on how to perform a certain action if the user has visited the site before?

  • @Moh_ha
    @Moh_ha 4 года назад +3

    This was very helpful thank you man!

  • @ArchanaKumari-ci1sx
    @ArchanaKumari-ci1sx 4 года назад +1

    Tip:
    Use autosave and liveserver for automatic saving as well as refreshing the page.

  • @ayen0449
    @ayen0449 2 года назад

    you're appreciated for this masterpiece. made this so easy to understand: THANKS

  • @mrjeevy7720
    @mrjeevy7720 10 месяцев назад

    Really good explanation, cheers!

  • @baseplate_462
    @baseplate_462 6 месяцев назад

    guy named DOM teaching us web development. Golden💀

  • @jogoeire
    @jogoeire 4 года назад

    Nice straightforward tut.

  • @emilianomedinaespinoza8822
    @emilianomedinaespinoza8822 Год назад

    awesome video, by the way what keyboard are you using? Sounds smooth and very comfy xD

  • @ercntreras
    @ercntreras 3 года назад

    A complete explanation and very clear. 🙏🏼

  • @akshayrc
    @akshayrc 3 года назад

    Very well explained and demonstrated.. Thanks!

  • @josiahtobas9172
    @josiahtobas9172 4 года назад +4

    Thanks a lot man, I'm currently looking for solutions of mimicking php sessions on the client side. Basically to really have separation of UI and Application layer logic. God bless.

  • @rioma3112
    @rioma3112 4 года назад

    Thanks man. This is a very good tutorial. Give this man props 👏🤝

  • @Raazor2232
    @Raazor2232 3 года назад

    Oh that upward inflection at the end of sentences. A fellow aussie

  • @ankitkumarjat9886
    @ankitkumarjat9886 4 года назад +3

    I know the basic things in html css and javascript but I want to learn in more deep like I learn fieldset tag here can you suggest me some source to learn and your videos are awesome.
    Love from india ❤️

  • @inayathkhan100
    @inayathkhan100 3 года назад

    Very useful tutorial, you'r the BEST!

  • @طالبالدعاء-ط9ق
    @طالبالدعاء-ط9ق 4 года назад +1

    You are great teacher
    Thanks a lott

  • @Jc-handle-with-care
    @Jc-handle-with-care 3 года назад

    Thanks that s an amazing tutorial! i really hope you re a teacher , you got skills!

  • @adrianibarra9589
    @adrianibarra9589 4 года назад

    Thanks man!!! This really helped me finish my project! Great tutorial

  • @Mohammad-lu1pp
    @Mohammad-lu1pp 3 года назад

    thank u so much, that will help improve my project a lot

  • @el9delcielo
    @el9delcielo 4 года назад

    i was expecting more than ONE item at the end. Given how you made a loop and all. Would also like to know why you would declare all variables as cons instead of just var? Other than that, great video. Thank you

  • @niloofar9113
    @niloofar9113 3 года назад

    This was awesome! Thank you for the simplicity~ :)

  • @doston38
    @doston38 4 года назад +1

    Hello bro, this is a very useful course. thank you

  • @MrAer85
    @MrAer85 3 года назад

    Got it working! Awesome!

  • @lulusaikou221
    @lulusaikou221 2 года назад

    Useful~ Thanks for teaching❤

  • @phodzonditsheni7914
    @phodzonditsheni7914 Год назад

    Great Video. Keep it up🔥🔥

  • @rumeysamert8373
    @rumeysamert8373 4 года назад +3

    question: do the items show up on the screen once you close the tab and open it again later? I know that he said that it would be saved in the local storage and stay there for a long time but I still wanted to ask.

  • @adagordon7029
    @adagordon7029 4 года назад

    Thank you very much for your lesson, it's pretty laconic & clear!

  • @chadrackkyungu2167
    @chadrackkyungu2167 4 года назад +1

    thank you it's was helpfull

  • @samcodes2912
    @samcodes2912 3 года назад

    love the explanation. straight to the point 👍

  • @noobCoder26
    @noobCoder26 2 года назад

    thanks for the video

  • @umbertopolanco4159
    @umbertopolanco4159 2 года назад

    Thank you very much for sharing your knowledge. This helped me greatly. Do you have a video for the same but for server side?

  • @legendarymc9384
    @legendarymc9384 5 лет назад +4

    It works but for temporary.

  • @FlexOffenders
    @FlexOffenders 6 лет назад +2

    Great video ! Thanks for the help.

  • @hopehope5064
    @hopehope5064 3 года назад

    Thank you a lot you really came through

  • @martinkarugaba
    @martinkarugaba 2 года назад

    Thanks man.

  • @codermans2350
    @codermans2350 4 года назад +1

    is there a way to add the values from local Storage?

  • @aryanheravitalemi8293
    @aryanheravitalemi8293 3 года назад

    Very helpful, thank you

  • @tunglam1321
    @tunglam1321 5 лет назад +1

    Great Video and Thank you!
    I have some question here want to ask.
    I want to know why it is worked on using const in the JavaScript assigning the variable, in my knowledge const means assign the variable one time only, but here is running the loop, so it shouldn’t assign one time only.
    I want to know where is my confused concept in const

    • @angelcaru
      @angelcaru 5 лет назад +1

      It isn't actually asigning It multiple times. Because const is block scope, It creates multiple constants

  • @rahulsharma7990
    @rahulsharma7990 3 года назад

    outstanding

  • @lightcode6487
    @lightcode6487 3 года назад

    So That means the input you're going to create is going to be saved to the localStorage and in your code, it will also display on the page. What if I refresh it? Will the input still be displayed? And nice video!

  • @dan112in69
    @dan112in69 4 года назад

    nice explained. thx

  • @umbertopolanco4159
    @umbertopolanco4159 3 месяца назад

    How can I keep adding to the same key more data? like if it was an Array that I keep pushing data to it.

  • @SuPaMaNallday
    @SuPaMaNallday 3 года назад +1

    FYI: Another way to add local storage and clear them (no code required).
    1. Open Dev Tools(f12).
    2. Select “Application”.
    3. Select “Local Storage” (located under the Storage section).
    4. Select Select the domain name that your on.
    5. Right Click underneath the “Key” field.
    6. Select “Add new” to enter a new key followed by a value. Or Select delete to remove and clear your storage.
    7. Above value there’s a cancel icon you can click on to clear all of your local storage.

  • @lingsike3193
    @lingsike3193 6 лет назад +1

    Hi I have a question about this tutorial. When I did the last step as "output.innerHTML += `${key}: ${value} `;" my console shows innerHTML as property undefined innerHTML as null. I added if state to check document.getElementById('output') !== null
    error went away but the div id ="output" won't show any date being added to localStorage

    • @dcode-software
      @dcode-software  6 лет назад

      Hey there, can you post your code? I'm struggling to understand

    • @SuryanshSingh-f8d
      @SuryanshSingh-f8d 5 лет назад

      Add the whole script in windowonload=function{
      Your whole script
      }

  • @Rs-nh7zx
    @Rs-nh7zx 3 года назад

    Great tutorial! Just wondering, how can I remove items with a button ? Like remove button ?

  • @priyaphilip5979
    @priyaphilip5979 2 года назад

    hi Your video was very helpful, though I have a problem...I didnt get the last line of the code and on VSC i didnt get the output as well(displaying on the div tag)...

  • @henilpatel9249
    @henilpatel9249 3 года назад

    Hi, I recently came up with some questions. So when you stored the user input in the local storage and then output it on the screen.
    - Can we do that with multiple users' responses, and if so, will all that users' data get deleted after refreshing or closing the webpage.
    - How do we prevent the data from getting deleted everytime we refresh the webpage or close the tab and come back in to see if the results are still stored in.
    Please help me with those 3 questions

  • @amjadshadid90
    @amjadshadid90 3 года назад

    great video, thank you

  • @lightcode6487
    @lightcode6487 3 года назад

    So the value stores in LocalStorage but nothing is displaying on the page..

  • @paulmonde6896
    @paulmonde6896 6 лет назад +2

    Great ! Thx man.

  • @saisrisai9649
    @saisrisai9649 4 года назад

    Thank you so much.

  • @mastercode7851
    @mastercode7851 4 года назад

    great stuff , thanks bro

  • @abhisheaka3277
    @abhisheaka3277 3 года назад

    Thanks man! , can you explain how can we update and delete the data which we entered?

  • @FrostDrive
    @FrostDrive 2 года назад

    When I put console.log(localStorage); in the console, or try any methods, I just get undefined

  • @freekiad1931
    @freekiad1931 3 года назад

    Thanks for the video, and My question is that, We take permission from the user for Read External Storage Data, and when I run this app in my device it asked me for permission but I want to know that when I gave permission to Mobile App read my data, so where and how app developer can read or see user mobile data ?
    Is that user data storage on my online storage server ?

  • @ragtop63
    @ragtop63 4 года назад

    Would localStorage be the proper way to store table data?
    For example, imagine you wrote a script that parses certain pages you browse for specific data. It takes that data and puts it into CSV format with the intent that it can later be read and placed into an HTML table. The amount of rows for the table (CSV) can be over 1000 rows.
    Is localStorage an acceptable solution for this scenario or is there a better method?

  • @tjmcode5187
    @tjmcode5187 2 года назад

    sir please how does the localstorage function when you host the website.

  • @jvnxs7
    @jvnxs7 3 года назад

    Nice video, thanks

  • @DeRhazzify
    @DeRhazzify 4 года назад

    How can you save the positon of drag & drop objects in localStorage? For example when you move a note on a board and then save its new location when you reload.

  • @lonewolfcoding5208
    @lonewolfcoding5208 3 года назад

    yes it works but i need more storage like sqlite
    and i want to access internal storage of phone

  • @asmapatel6127
    @asmapatel6127 2 года назад

    If I have live chat integrated with my app, can I store values from that live chat and somehow display it on my app page?

  • @mohammadbelalalzoubi8102
    @mohammadbelalalzoubi8102 6 лет назад +1

    It is great. Thank you.

    • @dcode-software
      @dcode-software  6 лет назад

      All good mate cheers good to see it helped you!

  • @ragunath7950
    @ragunath7950 3 года назад

    Final in inner.html is it essential to use $ for key and value symbol there.

  • @kamola9142
    @kamola9142 3 года назад

    Thank you

  • @lunleong4438
    @lunleong4438 5 лет назад

    How to get the update data after update the existing value in the localstorage without reload page?

  • @deki90to
    @deki90to 3 года назад

    when I type location.reload(); it keep realoding the page, why?

  • @adityajha1889
    @adityajha1889 3 года назад

    i have a question dcode. What happens when you add another name. Does it replace the other one or does it add another one

  • @EllantEladar37
    @EllantEladar37 2 года назад +1

    Sir dcode how do I create a remove button for localStorage.removeItem()?

    • @murgan4307
      @murgan4307 Год назад

      In local storage already into mark is there you can see that one

  • @Venkatnemala
    @Venkatnemala 4 года назад

    is it possible to fetch data localhost using inspect element

  • @siddharthjadhav3920
    @siddharthjadhav3920 4 года назад

    Hi , how to read key for google.com. I tried but i am unable to get value for the google website. Please help

  • @mauriciozapata3859
    @mauriciozapata3859 3 года назад

    anyone else getting a cannot read property 'value' for the button onclick function? where is value being declared? I"m only getting the error on the const key = inpKey.value but not on the Const value = inpValue.value. Very strange

  • @d0ma1n
    @d0ma1n 2 года назад

    Hi, is it possible to put function in localstorage that will load when it redirects to other page? I have a button on index.html and it needs to redirect on other page, and invoke a function, or button that has a function? Thanks

  • @mrfrontend1
    @mrfrontend1 2 года назад

    💥🔥

  • @jimh7604
    @jimh7604 5 лет назад

    When I insert a key and a value and press insert I get a window reload and the Local Storage fieldset doesn't get updated. Why is that? If I remove location.reload only then it works fine.

  • @Andrii87
    @Andrii87 3 года назад

    does data go away, when you close browser?

  • @sounak2009
    @sounak2009 5 лет назад

    Hi Dom.. The localstorage doesn't work on file protocol right?

  • @yuvrajkorotana7631
    @yuvrajkorotana7631 2 года назад

    How to display changes made in one webpage to reflect in the same webpage open separately like a comment box.

  • @naqashsakhawat4437
    @naqashsakhawat4437 5 лет назад

    I am facing error "Uncaught TypeError: Cannot set property 'onclick' of null" while i am just following your code for practice.

    • @dcode-software
      @dcode-software  5 лет назад +1

      Make sure you have the element. Check and ensure your IDs match up

  • @FloraT0106
    @FloraT0106 5 лет назад +12

    the way you named every variables makes students confused

    • @zvladd
      @zvladd 4 года назад +2

      looool. The explanation is great, the video is very helpful, but yes, I thought the same thing, not so sure about the variables names ... haha

    • @deki90to
      @deki90to 3 года назад

      use your own variables, its harder but it helps connect things, that way you can not just typing what you see, you also need to think what you type

  • @alexpopov5971
    @alexpopov5971 3 года назад

    How come I find that now?! What a life saver, it is exactly what I needed! Thank you!

  • @sumi-p5660
    @sumi-p5660 2 года назад

    How do i get unique id in localstorage?

  • @cafelutsa_
    @cafelutsa_ 4 года назад

    what if i want to store more names?

  • @jamajamajajajamajka
    @jamajamajajajamajka 6 лет назад +2

    why do you use $ sign in: '${key}'?...

    • @dcode-software
      @dcode-software  6 лет назад +4

      This takes advantage of the ES2015 feature, Template Literals and the ${ } means that it's a placeholder for an expression - so essentially it lets me output the value of the property rather than a dollar sign and a few curly braces. Learn more here
      developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

    • @thewukong4636
      @thewukong4636 5 лет назад

      its basically jquery

  • @ze_chooch
    @ze_chooch 4 года назад

    Oh hey. I'm Dom too.