<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Remove Local Storage &#8211; Sibeesh Passion</title>
	<atom:link href="https://www.sibeeshpassion.com/tag/remove-local-storage/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.sibeeshpassion.com</link>
	<description>My passion towards life</description>
	<lastBuildDate>Wed, 11 Jul 2018 16:28:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>/wp-content/uploads/2017/04/Sibeesh_Passion_Logo_Small.png</url>
	<title>Remove Local Storage &#8211; Sibeesh Passion</title>
	<link>https://www.sibeeshpassion.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Remove Filtered sessionStorage And localStorage</title>
		<link>https://www.sibeeshpassion.com/remove-filtered-sessionstorage-and-localstorage/</link>
					<comments>https://www.sibeeshpassion.com/remove-filtered-sessionstorage-and-localstorage/#disqus_thread</comments>
		
		<dc:creator><![CDATA[SibeeshVenu]]></dc:creator>
		<pubDate>Tue, 11 Aug 2015 00:32:47 +0000</pubDate>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Storage In HTML5]]></category>
		<category><![CDATA[Find Out Particular Local Storage And Delete]]></category>
		<category><![CDATA[Find Out Particular Session Storage And Delete]]></category>
		<category><![CDATA[Local Storage]]></category>
		<category><![CDATA[Remove Filtered sessionStorage And localStorage]]></category>
		<category><![CDATA[Remove Local Storage]]></category>
		<category><![CDATA[Remove session storage]]></category>
		<category><![CDATA[Session Storage]]></category>
		<category><![CDATA[Storage in HTML5]]></category>
		<guid isPermaLink="false">http://sibeecst_passion.com/?p=8541</guid>

					<description><![CDATA[[toc] Introduction In this post we well discuss how to remove all local storage and session storage or remove the storage according to the key values, for example, is a key contain a particular string, we will remove that local storage and session storage. We will find all the local storage and session storage first and then we will loop through each, if a user needs to delete a particular storage according to a particular condition, we will delete that storage alone. Both localStorage and sessionStorage has been introduced with HTML5. If you are new to storage mechanism in client [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>[toc]</p>
<h3>Introduction</h3>
<p>
In this post we well discuss how to remove all local storage and session storage or remove the storage according to the key values, for example, is a key contain a particular string, we will remove that local storage and session storage. We will find all the local storage and session storage first and then we will loop through each, if a user needs to delete a particular storage according to a particular condition, we will delete that storage alone. </p>
<p>Both <em>localStorage</em> and <em>sessionStorage </em>has been introduced with HTML5. If you are new to storage mechanism in client side, you can find out here: <a href="http://sibeeshpassion.com/tag/storage-in-html5/" target="_blank">Storage In HTML5</a>
</p>
<h3>Backgroud</h3>
<p>
I am working in a client-side application where we use <em>localStorage</em> and <em>sessionStorage </em> for saving some key informations. What I mean by key information is, like we store the mail id of the user who uses the application. There I got a requirement of deleting the <em>localStorage</em> and <em>sessionStorage </em> according to the key value. For example, I needed to delete the storage values whose keys start with &#8220;logged&#8221;. I did the requirement and thought to share with you all. I hope someone will find it is useful.
</p>
<h3>Using the code</h3>
<p>
To start with you need to include jquery reference.</p>
<p>[js]<br />
 &lt;script src=&quot;https://code.jquery.com/jquery-2.1.4.min.js&quot;&gt;&lt;/script&gt;<br />
[/js]</p>
<p>Now we need to set the <em>localStorage</em> and <em>sessionStorage </em> right? </p>
<p>Add the storage values in the ready event.</p>
<p>[js]<br />
localStorage.setItem(&quot;First1&quot;,&quot;First Local Storage&quot;);<br />
			sessionStorage.setItem(&quot;First1&quot;,&quot;First Session Storage&quot;);<br />
			localStorage.setItem(&quot;Second1&quot;,&quot;Second Local Storage&quot;);<br />
			sessionStorage.setItem(&quot;Second1&quot;,&quot;Second Session Storage&quot;);<br />
[/js]</p>
<p>So we have set our <em>localStorage</em> and <em>sessionStorage </em>. Now we need to check whether it is saved or not right? Just run your page and see your browser console.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage1.png"><img fetchpriority="high" decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage1-1024x256.png" alt="Remove_Filtered_sessionStorage_And_localStorage1" width="634" height="159" class="alignnone size-large wp-image-8551" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage1-1024x256.png 1024w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage1-300x75.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage1-768x192.png 768w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage1-400x100.png 400w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage1.png 634w" sizes="(max-width: 634px) 100vw, 634px" /></a></p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage2-e1438859495855.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage2-e1438859495855.png" alt="Remove_Filtered_sessionStorage_And_localStorage2" width="650" height="177" class="alignnone size-full wp-image-8561" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage2-e1438859495855.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage2-e1438859495855-300x82.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage2-e1438859495855-400x109.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Now we will add some elements where we can fire the delete events. Cool?</p>
<p>[html]<br />
 &lt;a href=&quot;#&quot; id=&quot;removeAllLocalStorage&quot;&gt;Click To Remove All Local Storage&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
   &lt;a href=&quot;#&quot; id=&quot;removeAllLocalStorageWhichStarts&quot;&gt;Click To Remove All Local Storage Which Starts With &quot;First&quot;&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
   &lt;a href=&quot;#&quot; id=&quot;removeAllSessionStorage&quot;&gt;Click To Remove All Session Storage&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
   &lt;a href=&quot;#&quot; id=&quot;removeAllSessionStorageWhichStarts&quot;&gt;Click To Remove All Session Storage Which Starts With &quot;First&quot;&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
[/html]</p>
<p>Once that is done, we add the click event scripts.</p>
<p>[js]<br />
 &lt;script&gt;<br />
       $(document).ready(function(){<br />
			localStorage.setItem(&quot;First1&quot;,&quot;First Local Storage&quot;);<br />
			sessionStorage.setItem(&quot;First1&quot;,&quot;First Session Storage&quot;);<br />
			localStorage.setItem(&quot;Second1&quot;,&quot;Second Local Storage&quot;);<br />
			sessionStorage.setItem(&quot;Second1&quot;,&quot;Second Session Storage&quot;);</p>
<p>            $(&quot;#removeAllLocalStorage&quot;).click(function(){<br />
				Object.keys(localStorage)<br />
				.forEach(function (key) {<br />
						localStorage.removeItem(key);<br />
				});<br />
            });<br />
			$(&quot;#removeAllLocalStorageWhichStarts&quot;).click(function(){<br />
				Object.keys(localStorage)<br />
				.forEach(function (key) {<br />
						if ((/^First/.test(key))) {<br />
							localStorage.removeItem(key);<br />
						}<br />
				});<br />
            });<br />
			$(&quot;#removeAllSessionStorage&quot;).click(function(){<br />
				Object.keys(sessionStorage)<br />
				.forEach(function (key) {<br />
						sessionStorage.removeItem(key);<br />
				});<br />
            });<br />
			$(&quot;#removeAllSessionStorageWhichStarts&quot;).click(function(){<br />
				Object.keys(sessionStorage)<br />
				.forEach(function (key) {<br />
						if ((/^First/.test(key))) {<br />
							sessionStorage.removeItem(key);<br />
						}<br />
				});<br />
            });<br />
       });<br />
      &lt;/script&gt;<br />
[/js]	 </p>
<p>So everything is set. Now the only pending thing is just run and see the output. </p>
<p>First, we will fire the click event which removes all the local storage. ok? </p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage3-e1438859851133.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage3-e1438859851133.png" alt="Remove_Filtered_sessionStorage_And_localStorage3" width="650" height="266" class="alignnone size-full wp-image-8581" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage3-e1438859851133.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage3-e1438859851133-300x123.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage3-e1438859851133-400x164.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Once you clicked, you can see all of your local storage items have been removed.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage4-e1438859935922.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage4-e1438859935922.png" alt="Remove_Filtered_sessionStorage_And_localStorage4" width="650" height="102" class="alignnone size-full wp-image-8591" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage4-e1438859935922.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage4-e1438859935922-300x47.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage4-e1438859935922-400x63.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Now we will reload the page and set the storage items again, this time we will fire the event which delete the local storage value which has key starts with &#8220;First&#8221;.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage5-e1438860090376.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage5-e1438860090376.png" alt="Remove_Filtered_sessionStorage_And_localStorage5" width="650" height="264" class="alignnone size-full wp-image-8601" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage5-e1438860090376.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage5-e1438860090376-300x122.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage5-e1438860090376-400x162.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Once you clicked you can see only the storage element which has key starts with &#8220;First&#8221; has been removed.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage6-e1438860182653.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage6-e1438860182653.png" alt="Remove_Filtered_sessionStorage_And_localStorage6" width="650" height="101" class="alignnone size-full wp-image-8611" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage6-e1438860182653.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage6-e1438860182653-300x47.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage6-e1438860182653-400x62.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Next, we will fire the click event which removes all the session storage. ok? </p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage7-e1438860272461.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage7-e1438860272461.png" alt="Remove_Filtered_sessionStorage_And_localStorage7" width="650" height="285" class="alignnone size-full wp-image-8621" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage7-e1438860272461.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage7-e1438860272461-300x132.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage7-e1438860272461-400x175.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Once you clicked, you can see all of your session storage items have been removed.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage8-e1438860363488.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage8-e1438860363488.png" alt="Remove_Filtered_sessionStorage_And_localStorage8" width="650" height="121" class="alignnone size-full wp-image-8631" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage8-e1438860363488.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage8-e1438860363488-300x56.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage8-e1438860363488-400x74.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Now we will reload the page and set the storage items again, this time we will fire the event which deletes the session storage value which has key starts with &#8220;First&#8221;.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage9-e1438860452170.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage9-e1438860452170.png" alt="Remove_Filtered_sessionStorage_And_localStorage9" width="650" height="280" class="alignnone size-full wp-image-8641" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage9-e1438860452170.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage9-e1438860452170-300x129.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage9-e1438860452170-400x172.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>Once you clicked you can see only the session storage element which has key starts with &#8220;First&#8221; has been removed.</p>
<p><a href="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage10-e1438860535759.png"><img decoding="async" src="http://sibeeshpassion.com/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage10-e1438860535759.png" alt="Remove_Filtered_sessionStorage_And_localStorage10" width="650" height="126" class="alignnone size-full wp-image-8651" srcset="/wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage10-e1438860535759.png 650w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage10-e1438860535759-300x58.png 300w, /wp-content/uploads/2015/08/Remove_Filtered_sessionStorage_And_localStorage10-e1438860535759-400x78.png 400w" sizes="(max-width: 650px) 100vw, 650px" /></a></p>
<p>So we have done everything.
</p>
<h3>Complete Code</h3>
<p>
[html]<br />
&lt;html&gt;<br />
   &lt;head&gt;<br />
      &lt;title&gt;Remove all session storage,local storage or remove by key which starts with a particular string &#8211; Sibeesh Passion&lt;/title&gt;<br />
      &lt;script src=&quot;https://code.jquery.com/jquery-2.1.4.min.js&quot;&gt;&lt;/script&gt;<br />
   &lt;/head&gt;<br />
   &lt;body&gt;<br />
   &lt;a href=&quot;#&quot; id=&quot;removeAllLocalStorage&quot;&gt;Click To Remove All Local Storage&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
   &lt;a href=&quot;#&quot; id=&quot;removeAllLocalStorageWhichStarts&quot;&gt;Click To Remove All Local Storage Which Starts With &quot;First&quot;&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
   &lt;a href=&quot;#&quot; id=&quot;removeAllSessionStorage&quot;&gt;Click To Remove All Session Storage&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
   &lt;a href=&quot;#&quot; id=&quot;removeAllSessionStorageWhichStarts&quot;&gt;Click To Remove All Session Storage Which Starts With &quot;First&quot;&lt;/a&gt;&lt;br/&gt;&lt;br/&gt;<br />
   &lt;div id=&quot;body&quot;&gt;&lt;/div&gt;<br />
      &lt;script&gt;<br />
       $(document).ready(function(){<br />
			localStorage.setItem(&quot;First1&quot;,&quot;First Local Storage&quot;);<br />
			sessionStorage.setItem(&quot;First1&quot;,&quot;First Session Storage&quot;);<br />
			localStorage.setItem(&quot;Second1&quot;,&quot;Second Local Storage&quot;);<br />
			sessionStorage.setItem(&quot;Second1&quot;,&quot;Second Session Storage&quot;);</p>
<p>            $(&quot;#removeAllLocalStorage&quot;).click(function(){<br />
				Object.keys(localStorage)<br />
				.forEach(function (key) {<br />
						localStorage.removeItem(key);<br />
				});<br />
            });<br />
			$(&quot;#removeAllLocalStorageWhichStarts&quot;).click(function(){<br />
				Object.keys(localStorage)<br />
				.forEach(function (key) {<br />
						if ((/^First/.test(key))) {<br />
							localStorage.removeItem(key);<br />
						}<br />
				});<br />
            });<br />
			$(&quot;#removeAllSessionStorage&quot;).click(function(){<br />
				Object.keys(sessionStorage)<br />
				.forEach(function (key) {<br />
						sessionStorage.removeItem(key);<br />
				});<br />
            });<br />
			$(&quot;#removeAllSessionStorageWhichStarts&quot;).click(function(){<br />
				Object.keys(sessionStorage)<br />
				.forEach(function (key) {<br />
						if ((/^First/.test(key))) {<br />
							sessionStorage.removeItem(key);<br />
						}<br />
				});<br />
            });<br />
       });<br />
      &lt;/script&gt;</p>
<p>   &lt;/body&gt;<br />
&lt;/html&gt;<br />
[/html]
</p>
<h3>Conclusion</h3>
<p>
Thanks a lot for reading. Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.
</p>
<h3>Your turn. What do you think?</h3>
<p>
A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.
</p>
<p>Kindest Regards<br />
Sibeesh Venu</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.sibeeshpassion.com/remove-filtered-sessionstorage-and-localstorage/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
