[英]How to set up a variable = to a key in local storage
I try to create a variable with the key of my local storage as it value.我尝试使用本地存储的键创建一个变量作为它的值。
i tried let justId = localStorage.key
我试过
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但是我在控制台中得到的响应只是
ƒ key() { [native code] }
而我无法在我的代码中使用它
Could you help me with that ?你能帮我解决这个问题吗? Thanks in advance
提前致谢
To get and item or value from the localStorage
, first you need to set a value.要从
localStorage
获取项目或值,首先需要设置一个值。
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.key
用于使用value
获取key
localStorage.setItem('name', 'My Name')
var myKey = localStorage.key('MyName')
console.log(myKey)
// logs 'name'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.