localstorage
localstorage.setItem("rajiv","dahal")
here 'rajiv; is key and 'dahal ' is value
localstorage..getItem("rajiv")
output is "dahal"
localstorage.ramoveItem("rajiv")
the value is removed
problem in localstorage
const user={name:'rajiv'}
localstorage.setItem("name":user)
output:
here [object:object] will be shown in value but we want {name:rajiv'}
so we use JSON for this type of problem
localstorage.setItem('name':JSON.stringify(user))
output: 'name' {"'name'":"rajiv"}
localstorage.getItem("name")
output: {'name':'rajiv'}
but we want{name:'rajiv'}
so to print output we use parse i.e
Comments
Post a Comment