In this article, we will see, what are LocalStorage and SessionStorage? How we can use it? and what are the advantages and disadvantages?.
Both are an object of web storage, which allow us to save key/value pairs in the browser instead of a server. Both have some advantages and disadvantages.
As the name suggests, its saves/store data in client local machine in key/value pair, Its also known as DOM storage.
session storage saves/store data in client local machine in key/value pair for the current origin.
Both storage objects provide the same methods:
setItem(key, value)
– which store a key/value pair.getItem(key)
– which gets the value by key.removeItem(key)
– which removes the key with its value.clear()
– which deletes everything from storage.key(index)
– which gets the key in a given position.length
– which returns the number of stored items.setItem(key, value)
localStorage.setItem('Name', 'Faisal'); sessionStorage.setItem('Name', 'Faisal');
getItem(key)
localStorage.getItem('Name'); sessionStorage.getItem('Name');
localStorage.setItem('Name', JSON.stringify({name: "John"})); sessionStorage.setItem('Name', JSON.stringify({name: "John"}));
JSON.parse(localStorage.getItem('Name')); JSON.parse(sessionStorage.getItem('Name'));
hope you guys found something useful. Please give your valuable feedback/comments/questions about this article. Please let me know how you like and understand this article and how I could improve it.
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular