0

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

MddHtt13
  • 365
  • 1
  • 3
  • 10
  • 1
    Do you simply want to persist it somewhere, or are you trying to make the data accessible to an external (native) progam? – Beartums Jan 17 '15 at 07:48
  • I was just looking to collect a bunch of words and store them into an array for later reference. – MddHtt13 Jan 17 '15 at 08:35
  • I would then use this to pull words from at random for other programs. – MddHtt13 Jan 17 '15 at 08:41
  • Your browser will not be able to write to a file in the local file system. If you need to access it from other web applications, you can might be able to use window.localStorage. Probably the easiest it to set up local DB - mysql, sqlexpress, mongodb, couchdb, or some such that you can access from within a web application or through a native application. – Beartums Jan 17 '15 at 09:49

1 Answers1

0

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.

Patriot
  • 314
  • 3
  • 17