I have a function that gets all the keys of local storage and sends it to you via email:
function sendLocalStorageByEmail(recipient) {
// create localstorage string
var output = "";
for (var key in localStorage) {
output += key + "\n";
output += localStorage[key] + "\n";
output += "\n";
}
// create temporary anchor to emulate mailto click in new tab
var anchor = document.createElement("a");
anchor.href = "mailto:" + recipient + "?subject=Names for tonight&body=" + encodeURIComponent(output);
anchor.style.display = "none";
anchor.setAttribute("target", "_blank");
anchor.appendChild(document.createTextNode(""));
document.body.appendChild(anchor);
if (anchor.click) {
return anchor.click();
}
Since the keys are a four digit number I would like to sort them via numerical order first. My question is, since localstorage data is stored as an string, and most sorting is done via an array. Am I going to have to convert it to a array, and then back again?
If someone can help me with this, it would be much appreciated.
1 Answer