return 如果本地存储中存在数组则为 false?
return false if array exist in localstorage?
var arr= new Array();
arr.push("John");
localStorage["name"] = JSON.stringify(arr);
如何查看localstorage中是否存在John?获得值后下一步该做什么?
JSON.parse(localStorage["name"]);
JSON.parse( localStorage["name"] ).indexOf('John3')
return-false-if-array-exist-in-localstorage
JSON.parse(localStorage["name"]).indexOf("John") !== -1 ? false : true;
要 添加 一个值到 localStorage
,使用语法
localStorage.setItem("key", "value");
要从localStorage
中检索一个值,使用语法
var data = localStorage.getItem("key");
按照你的例子,你会做类似的事情
var arr = ['John'];
localStorage.setItem("name", JSON.stringify(arr));
并且检查元素 'John' 是否存在于数组中是微不足道的:
var arr = JSON.parse(localStorage.getItem("name"));
if (arr.indexOf("John") == -1) { // Array.indexOf() returns -1 if element not found
// Then "John" does not exist in the array
} else {
// "John" exists in the array
}
var arr= new Array();
arr.push("John");
localStorage["name"] = JSON.stringify(arr);
如何查看localstorage中是否存在John?获得值后下一步该做什么?
JSON.parse(localStorage["name"]);
JSON.parse( localStorage["name"] ).indexOf('John3')
return-false-if-array-exist-in-localstorage
JSON.parse(localStorage["name"]).indexOf("John") !== -1 ? false : true;
要 添加 一个值到 localStorage
,使用语法
localStorage.setItem("key", "value");
要从localStorage
中检索一个值,使用语法
var data = localStorage.getItem("key");
按照你的例子,你会做类似的事情
var arr = ['John'];
localStorage.setItem("name", JSON.stringify(arr));
并且检查元素 'John' 是否存在于数组中是微不足道的:
var arr = JSON.parse(localStorage.getItem("name"));
if (arr.indexOf("John") == -1) { // Array.indexOf() returns -1 if element not found
// Then "John" does not exist in the array
} else {
// "John" exists in the array
}