【发布时间】:2019-06-25 17:34:22
【问题描述】:
我正在尝试在 localStorage 值中保存一个数组。我只能访问值的字符,而不是分组值。我一直在尝试编写一个函数来用逗号对它们进行分组,但我不知道如何正确地做到这一点。
// setting values
localStorage.setItem("foo", [15,"bye"]);
// writes the whole thing.
document.write(localStorage.getItem("foo")); // returns 15,bye
// only writes the first character, instead of one part of the array
// (in this case it would be 15).
document.write(localStorage.getItem("foo")[0]); // returns 1
【问题讨论】:
标签: javascript html local-storage session-storage