I am working on a school project and any assistance would be greatly appreciated.
Upon execution in a browser like Chrome, the array below gets populated with data.
I am trying to determine how to store or update this array in a local file.
var listDataObject = {
reminderListArray: [{
title: "Sample one",
star: true,
checkbox: true
},
{
title: "Sample two",
star: false,
checkbox: false
}
]
};
In theory, I know that I need to convert the array into JSON format and then save it to a file.
I have also read about parsing the JSON data when retrieving it.
However, this is as far as I have progressed.
saveText(JSON.stringify(listDataObject), "filename.json");
function saveText(text, filename) {
var a = document.createElement('a');
a.setAttribute('href', 'data:text/plain;charset=utf-u,' + encodeURIComponent(text));
a.setAttribute('download', filename);
a.click();
}
For your reference, here is the complete script:
...