Let’s look at how to store JavaScript objects in the localStorage object using the setItem and getItem methods, as well as two JSON methods, stringify and parse.
setItem() – the setItem method is used to add data to a web storage object. It takes in two arguments, a key and value pair, window.localStorage.setItem("key", value)
getItem() – the getItem method returns the value of the key name that’s passed to it, such as window.localStorage.getItem("key name")
JSON.stringify – the JSON.stringify method converts any object or acceptable value into a string JSON
JSON.parse – the JSON.parse method converts a string into its corresponding object or value as described by the string
Local storage can only save strings, so storing objects requires that they be turned into strings using JSON. stringify - you can't ask local storage to store an object directly because it'll store “[object Object]”, which isn't right at all! That also means the object must be run through JSON.
Watch video How to store objects in HTML5 localStorage online without registration, duration hours minute second in high quality. This video was added by user Quick Code Academy 24 December 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 286 once and liked it 7 people.