HTML DOM স্টোরেজ getItem() পদ্ধতিটি একটি প্রদত্ত কী নাম পাস করে স্টোরেজ অবজেক্ট পাওয়ার জন্য ব্যবহার করা হয়। এটি কী-এর মান ফিরিয়ে দেবে এবং যদি সেই প্রদত্ত নামের কোন কী না থাকে তাহলে NULL ফেরত দেওয়া হবে।
সিনট্যাক্স
Storage getItem() মেথড -
-এর সিনট্যাক্স নিচে দেওয়া হলlocalStorage.getItem(keyname);
বা
sessionStorage.getItem(keyname);
এখানে, কী-নাম টাইপ স্ট্রিং এবং প্রাপ্ত করা আইটেমের নামের প্রতিনিধিত্ব করে।
উদাহরণ
আসুন আমরা HTML DOM স্টোরেজ getItem() পদ্ধতি -
-এর একটি উদাহরণ দেখি<!DOCTYPE html>
<html>
<body>
<h1 style="text-align:center">Storage getItem() method example</h1>
<p>Create a localStorage item with the name CLICKS to count the number of clicks on the create button by clicking the below button</p>
<button onclick="createItem()">CREATE</button>
<p>Get the CLICKS item value by clicking the below button</p>
<button onclick="showItem()">Display</button>
<p id="Sample"></p>
<script>
var y=1;
function createItem() {
document.getElementById("Sample").innerHTML="localStorage Item has been created with name CLICKS";
localStorage.visits = y;
y++;
}
function showItem() {
var x = localStorage.getItem("visits");
document.getElementById("Sample").innerHTML = "The total no. of clicks are : "+x;
}
</script>
</body>
</html> আউটপুট
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে

ক্রিয়েট বোতামে ক্লিক করলে -

"ডিসপ্লে" বোতামে ক্লিক করলে -
