I've got a file made using JavaScript that contains the contents of the localstorage for a website. It's been stringified and is (now) separated by "|". I want to split this string after every "|" into a separate string so I can 1 by 1 input each variable with its value into localstorage, as, from what I know, you can't set multiple items at once. Here's what I've got so far but after researching I've yet to find a solution other than putting into an array...
<input type="file" id="file" accept=".io">
<div id="contents"></div>
<script>
var X;
document.getElementById('file').addEventListener('change',
function () {
var fr = new FileReader();
fr.onload = function () {
document.getElementById('contents').textContent =
this.result.replace(/,/g,"|").replace(/:/g,",").slice(1,-1);
};
fr.readAsText(this.files[0]);
}
);
localStorage.setItem("test","1223asd3423");
</script>
I have a feeling that what I'm doing is an elongated and inefficient way to export/import localstorage data and there's some sort of solution containing an amalgam of for
loops and other forms of JavaScript I'm yet to branch into as a novice.
Here is an example of how the raw file is formatted just for reference:
Settings.io: (.io file extension, not website domain)
{"AB12_Rubicon":"37","AB9":"99","backgroundColor":"#2e2e2e",....}
The new string
"AB12_Rubicon","37"|"AB9","99"|"backgroundColor","#2e2e2e"|....
example of desired result
Newstring1 = '"AB12_Rubicon","37"'; Newstring2 = '"AB9","99"';