0

I am trying to retreive key of a value which is in the browser local storage

But it returns same key for values which are stored in local storage but when i try to get value from key it give correct value.

see here

I am trying to remove active element from html as well as its data which is stored in localstorage

function removefrom() {
   const element = document.activeElement;
   const key = localStorage.key(element.value);
   localStorage.removeItem(key);
   element.remove();

}

  1. first i will get active selected element
  2. i will pass active element's value from element.value (in line 2)
  3. then i want to get key where the that value is in localstorage and then i will find key from passed value
  4. in line 4, i will remove item from local storage from key
  5. i will remove element from the dom
pew-dew
  • 1
  • 2

1 Answers1

0

Maybe you can use something like this to fetch the values of keys stored in your local storage

for (let i = 0; i < localStorage.length; i++) {
  console.log(localStorage.getItem(localStorage.key(i)));
}

For more you can refer this link: https://developer.mozilla.org/en-US/docs/Web/API/Storage/key

Anuj Panchal
  • 391
  • 3
  • 15