Exporting data from a web browsers console to either the clipboard or a text file

118 Views Asked by At

I have written a function like so:

function wordSnatcher(element, startsWith) {
    var arrOfElem = document.getElementsByTagName(element);
    var nwArr = [];
    var tmp = "";
    for (var i = 0; i < arrOfElem.length; i++) {
        tmp = arrOfElem[i];
        if (tmp.textContent.charAt(0).toLowerCase() ==  startsWith.toLowerCase() && 
             tmp.textContent.length > 3) {
            nwArr.push(tmp.textContent);
        }
    }
    return nwArr.sort();
}

How this function would be implemented would look like this:

wordSnatcher('li', 'b');

The end result is an HTMLCollection of all words that start with the specified letter and reside in the specified element when executed in the console of a web browser.

So far I've been storing the array in a variable like this:

var b = wordSnatcher('li', 'b');

But this only gets me so far... I've been racking my brain trying to figure out how I can take this array and move it into an external JavaScript file. I can't copy it from the console using the clipboard, and I also can't seem to export it to a medium where I can grab it using the clipboard (like a .txt file)

If you merely iterate over the array and log it to the console it seems to, for some reason, only print out a portion of the arrays values

Besides that sort of defeats the purpose of what I'm trying to do because I want to keep it formatted as an array.

If you would like to try it exactly as I am trying it, use this function in the console while on this page: http://www.scrabblefinder.com/starts-with/b/

Doing this yields an array of over 5000 words, which is not easily manageable

1

There are 1 best solutions below

0
On

Post the array in JSON format to an external file that will handle it. You can store it as text, store in a database or push it to the client.