-4

I need a dictionary for my word game. I have it downloaded and I know the storage path. I have looked for an hour or two(with a couple short breaks) looking for solutions. They either didn't work or were too complicated for me to implement, although I did attempt most of them. I want it in an array-type format. Every new word is on a new line, so split can be '\n'. The dictionary is in the same folder as my js file, but if I need the full path, just use fullPath please. Use dictionary.txt for just the file.

I wish I had some code to get started, but as I said before, none of the ones I've tried work, and I have never done this before. Please help, it is necessary for my game.

  • 2
    *They either didn't work or were too complicated for me to implement* please share references to these solutions so we don't offer you the same ones. And please elaborate on what doesn't make them work. – Emiel Zuurbier Dec 10 '22 at 21:12

2 Answers2

-1

You could try to read the contents from a .txt file using the FileReader() class.

You mentioned that you split your words by a \n, you could use the FileReader() class to read the text file as an array, and then do some array splitting of the array given your \n. I am sure there are lots of ways to do this, this was the first thing that popped up when i searched for it online on google.

Read here more about it: https://developer.mozilla.org/en-US/docs/Web/API/FileReader

Frappe
  • 1
  • 1
-3

I found something as I was getting links. the code is as follows:

var client = new XMLHttpRequest();
  client.open('GET', '/scriptAndBank/dictionary.txt');
  client.onreadystatechange = function() {
    const dictionary = (client.responseText).split('\n');
    console.log(dictionary);
  };
client.send();