<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script>
//Add Key Value pair inside local Storage
localStorage.setItem('Name', 'Atul');
localStorage.setItem('Name2', 'Atul2');
//Getting an item from the local Storage
let name = localStorage.getItem('Name');
//Clears the entire local Storage
// localStorage.clear();
console.log(name);
//Removing A single item from Storage key value pair
localStorage.removeItem('Name2');
//Adding Array to localStorage...Normally if you save Browser will convert it into string
let impArray = ['Adrak', 'Pyaz', 'bhindi'];
localStorage.setItem('Sabji', JSON.stringify(impArray));
//Getting that saved Array String and converting it to normal Array
let x = localStorage.getItem('Sabji');
let y = JSON.parse(x);
console.log(y);
//['Adrak', 'Pyaz', 'bhindi'] now we can performe all operation related to JS Array
//Array ke sath fayeda hoga string manipulation mein
//Clearing all localStorage
localStorage.clear();
</script>
</body>
</html>
No comments:
Post a Comment