UPDATE: Saving arrays with multiple dimensions is now possible in the following format:
var a = ["t1","a",["t2","a","b",["t3","a","b"],["t4","a","b","c",["t5","a","b"]],],["t6","a","b",["t7","a","b"]]];
This data can be saved to a file using a standard save file function that utilizes JSON.stringify(a) - excluding the "var a = " and the ";" parts. To later access this data, follow these steps:
<a id="nof"><label for="fid">Open Data</label></a>
<input id="fid" type="file" style="position: fixed; top: -100em" onchange="ReadFile(this)">
function ReadFile(input) {
var output;
if (input.files.length === 0) {
output = 'No file selected';
window.setTimeout(ReadFile, 1000);
return;
}
var fr = new FileReader();
fr.onload = function() {
var data = fr.result;
var array = new Int8Array(data);
output = JSON.stringify(array, null, ' ');
console.log(array); // output
};
fr.readAsArrayBuffer(input.files[0]);
I attempted to modify code from the post found at: Using FileReader.readAsArrayBuffer() on changed files in Firefox, but encountered difficulties assigning the data as a JS array variable. The console displays numbers due to int8 conversion.
The "output" variable results in:
{"0": 91,"1": 34,"2": 116,"3": 49,"4": 32,"5": 118,"6": 49,"7": 57,"8": 49,"9": 49,"10": 49,"11": 53,"12": 49,"13": 56,"14": 49,"15": 51,"16": 52,"17": 48,"18": 34,"19": 44,"20": 34,"21": 97,"22": 34,"23": 44,"24": 91,"25": 34,"26": 116,"27": 50,"28": 34,"29": 44,"30": 34,"31": 97,"32": 34,"33": 44,"34": 34,"35": 98,"36": 34,"37": 44,"38": 91,"39": 34,"40": 116,"41": 51,"42": 34,"43": 44,"44": 34,"45": 97,"46": 34,"47": 44,"48": 34,"49": 98,"50": 34,"51": 93,"52": 44,"53": 91,"54": 34,"55": 116,"56": 52,"57": 34,"58": 44,"59": 34,"60": 97,"61": 34,"62": 44,"63": 34,"64": 98,"65": 34,"66": 44,"67": 34,"68": 99,"69": 34,"70": 44,"71": 91,"72": 34,"73": 116,"74": 53,"75": 34,"76": 44,"77": 34,"78": 97,"79": 34,"80": 44,"81": 34,"82": 98,"83": 34,"84": 93,"85": 93,"86": 93,"87": 44,"88": 91,"89": 34,"90": 116,"91": 54,"92": 34,"93": 44,"94": 34,"95": 97,"96": 34,"97": 44,"98": 34,"99": 98,"100": 34,"101": 44,"102": 91,"103": 34,"104": 116,"105": 55,"106": 34,"107": 44,"108": 34,"109": 97,"110": 34,"111": 44,"112": 34,"113": 98,"114": 34,"115": 93,"116": 93,"117": 93}
To successfully assign file data as a JS array, additional adjustments are required.
***Efficiency-focused users can stick with the provided example array structure on the page without resorting to more intricate formats.