如何在localStorage中存储数组?

时间:2016-02-18 09:05:30

标签: javascript json

我必须在# # Oracle Java 8 Dockerfile # # https://github.com/dockerfile/java # https://github.com/dockerfile/java/tree/master/oracle-java8 # # Pull base image. FROM debian:latest # Install Java. RUN \ apt-get update && \ echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee /etc/apt/sources.list.d/webupd8team-java.list && \ echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu trusty main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list && \ apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886 && \ apt-get update && \ dpkg -P oracle-java8-installer && \ apt-get install -f # Define commonly used JAVA_HOME variable ENV JAVA_HOME /usr/lib/jvm/java-8-oracle CMD["/bin/bash"] 中存储一个数组。如何使用控制台窗口将数组存储在window.localStorage中?

window.localStorage

我必须存储这个。现在这里的关键是卡片,长度是嵌套的。

1 个答案:

答案 0 :(得分:4)

localStorage仅支持string,因此您必须将其解析为JSON



var arr = ["hello", "how", "are", "you", "doing"];

localStorage.setItem("test", JSON.stringify(arr));




JSFiddle