export Data in localStorage for later re-import

后端 未结 5 668
既然无缘
既然无缘 2021-01-31 00:22

I want to export a few items from my localStorage to save it externally but in a format so that I can import it again later.

My attempt was to write executable code that

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-31 00:51

    You can encode Objects into Strings using JSON.stringify (object to String) and decode Strings into Objects using JSON.parse (String to Object).

    Write to localStorage

    localStorage.setItem("varname",JSON.stringify(originalVarname));
    

    Read from localStorage

    var originalVarname= JSON.parse(localStorage.getItem("varname"));
    

提交回复
热议问题