localstorage get set item js code example

Example 1: localstorage set item

localStorage.getItem('data')
localStorage.setItem('token', 'token here');
localStorage.removeItem('token');

Example 2: javascript storage get set item

// *** JS Storage Get/Set item *** 

	let target = document.getElementById("target");
    let increment = document.getElementById("increment");
    let count = localStorage.getItem("counter") || 0;
    target.innerHTML = count;

    increment.addEventListener("click", () => {
        count++;
        localStorage.setItem("counter", count);
        target.innerHTML = count;
    })

Tags:

Misc Example