How to create a multiple values for a single key using local storage

前端 未结 3 839
梦谈多话
梦谈多话 2021-01-06 02:14

As we all know local storage is a key value pair. Trying to create a multiple values to a single key. But unable to get how to pass the multiple values for a single key.

3条回答
  •  独厮守ぢ
    2021-01-06 02:45

    This is not possible with localstorage. However, you can store a JSON string as the value for the key, and with a little post-processing, you can extract your three variables:

    var value = ["aa","bb","cc"]
    localStorage.setItem("testKey", JSON.stringify(value));
    var test = JSON.parse(localStorage.getItem("testKey"));
    alert(test);
    

提交回复
热议问题