I am writing a webapp that utilizes localstorage. I have it setup now to save to the local storage with the following format:

Key: Four digit number
Value: My data

I need to take all the separate data from the localStorage, and output it to a single file with the following format:

XXXX <- Four digit key  

Data  

-linebreak-

How would I go about doing this? Also, is it possible to somehow take all this information, and send it via email. Or some way to get it out of localstorage and to clipboard so the user can copy it into their email.

Thanks ahead.
['https://Stackoverflow.com/questions/13672727', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1341539/']
```
var output = "";
for(var key in localStorage) { 
    output += key+"\n";
    output += localStorage[key]+"\n";
    output += "\n";
}

// output contains combined string

```

As for the email part you could try using a `mailto:` like this,

```
<a href='mailto:user@domain?subject=[subject here]&body=[email body here]'></a>

```

This could be combined into a function like this:

```
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=Local+Storage+Data&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();
    }

    // some browsers (chromium/linux) have trouble with anchor.click
    var clickEv = document.createEvent("HTMLEvents");
    clickEv.initEvent("click", true, true);
    anchor.dispatchEvent(clickEv)
}

```

Usage:

```
<a href='javascript:sendLocalStorageByEmail(prompt("Please enter your e-mail address"))'>
   Send Email
</a>

```
It is possible to integrate directly mail adress in the code, before mailto:

```
anchor.href = "mailto:*youradress@ttt.com*"+recipient+"? 
subject=Local+Storage+Data&body="+encodeURIComponent(output);

```