Simple LocalStorage SessionStorage using JavaScript – Technology

Simple LocalStorage SessionStorage using JavaScript – Technology

In this post we will give you information about Simple LocalStorage SessionStorage using JavaScript – Technology. Hear we will give you detail about Simple LocalStorage SessionStorage using JavaScript – TechnologyAnd how to use it also give you demo for it if it is necessary.

Today, We want to share with you Simple LocalStorage SessionStorage using JavaScript.In this post we will show you localstorage expiration, hear for how to store data in localstorage in javascript we will give you demo and example for implement.In this post, we will learn about with an example.

Simple LocalStorage SessionStorage using JavaScript

There are the Following The simple About Simple LocalStorage SessionStorage using JavaScript Full Information With Example and source code.

Another must read:  Laravel 5.5 Resolve errors The page has expired due to inactivity

As I will cover this Post with live Working example to develop session-storage vs local-storage, so the local storage javascript for this example is following below.

LocalStorage Introduction

  • setItem(): javascript simple Add key and value to local storage
  • getItem() : javascript get all a value by the key
  • removeItem() : delete or remove an item by key using javascript
  • clear() : (reset)Clear all storage in javascript

Local-storage Syntax

localStorage.setItem('key', 'value');
localStorage.getItem('key');
localStorage.removeItem('key');
localStorage.clear();

Checking for Browser Support

if (localStorage) {
  // LocalStorage is supported!
} else {
  // No LocalStorage support. 
}

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

//Storing Data in LocalStorage
localStorage.setItem('product_name', 'Iphone 8');

// Functions
localStorage.setItem('product_name', 'Iphone 8');

// Object
localStorage.product_name = 'Iphone 8';

// Array
localStorage['product_name'] = 'Iphone 8';

//get all Data from LocalStorage
var product_name = localStorage.getItem('product_name');

//Removing Data from LocalStorage
localStorage.removeItem('product_name');

//Retrieving Keys
for (var i = 0; i < localStorage.length; i++) {
  console.log(localStorage.key(i))
};

JavaScript SessionStorage

// JavaScript Storing Data
sessionStorage.setItem('product_name', 'Iphone 8');

// JavaScript get all the Data
var product_name = sessionStorage.getItem('product_name');

// Deleting Data in JavaScript
sessionStorage.removeItem('product_name');

// get all an Item Key
sessionStorage.key(n);

// Clearing the Datastore using JavaScript
sessionStorage.clear();

Storing Objects in JavaScript localStorage

var productObj = { 'iteam1': 'mobile', 'iteam2': 'laptop', 'iteam3': 'bags' };

// Put the object into storage
localStorage.setItem('productObj', JSON.stringify(productObj));

// get all the object from storage
var all_product_objects = localStorage.getItem('productObj');

console.log('all_product_objects: ', JSON.parse(all_product_objects));

Simple LocalStorage SessionStorage using JavaScript

<!DOCTYPE html>
<html>
<head>
<title>Window localStorage Property</title>
</head>
<body>
<h2>Window localStorage Property</h2>
<div id="response"></div>

<script>
// Check browser support
if (typeof(Storage) !== "undefined") {
    // Store
    localStorage.setItem("lastname", "Jaydeep");
    // Retrieve
    document.getElementById("response").innerHTML = localStorage.getItem("lastname");
} else {
    document.getElementById("response").innerHTML = "Sorry, your browser does not support Web Storage...";
}
</script>
<a href="https://onlinecode.org/" target="_blank" alt="onlinecode" title="onlinecode">Free Download Example - onlinecode</a>

</body>
</html>
Angular 6 CRUD Operations Application Tutorials

Read :

Another must read:  CKEditor Upload files Custom File Manager using PHP

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Simple LocalStorage SessionStorage using JavaScript.
I would like to have feedback on my onlinecode blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Hope this code and post will helped you for implement Simple LocalStorage SessionStorage using JavaScript – Technology. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

7  +  2  =  

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US