export Data in localStorage for later re-import

后端 未结 5 665
既然无缘
既然无缘 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:54

    Export

    copy(JSON.stringify(JSON.stringify(localStorage)));
    

    Import

    var data = JSON.parse(/*previously copied stringified JSON from clipboard*/);
    Object.keys(data).forEach(function (k) {
      localStorage.setItem(k, data[k]);
    });
    

提交回复
热议问题