Reputation: 35
I try to create a variable with the key of my local storage as it value.
i tried let justId = localStorage.key
but the response i got in the console is just ƒ key() { [native code] }
and i'm not able to use it on my code
Could you help me with that ? Thanks in advance
Upvotes: 2
Views: 2129
Reputation: 846
To get and item or value from the localStorage
, first you need to set a value.
localStorage.setItem('key', 'value');
// To get an item:
var result = localStorage.getItem('key');
The localStorage.key
is used to get the key
using the value
localStorage.setItem('name', 'My Name')
var myKey = localStorage.key('MyName')
console.log(myKey)
// logs 'name'
Upvotes: 2