2

I have a dictionary text file in the project folder and I would like to read it and put items in an array in my App.js file. How can I do that?

Here is how the project looks: Here

aleksandar3
  • 57
  • 1
  • 5
  • To be able to help I think more information is required. Is it an electron app or a browser app? When tloading the file will it be a user specified file or will it always be that static file? Are you wanting to read it at run time or are you bundling your app and want it to be read in then? – Mike Lowen Mar 19 '22 at 18:11
  • https://stackoverflow.com/questions/50539756/how-to-import-a-txt-file-from-my-source – Andy Mar 19 '22 at 18:11
  • By "items" do you mean things on separate lines? – Andy Mar 19 '22 at 18:15
  • 1
    Questions should have all required information not as external links, but *in the question*. Also, source code and directory listings will be as formatted text, *not* screenshots (use backticks/triple backticks as needed). You have not provided any detail on the input data format or any example code, leaving everyone to guess. – JGurtz Mar 19 '22 at 20:01
  • It is a browser app. It will always be that static file and the words are seperated by \n. I want to place them in array. – aleksandar3 Mar 20 '22 at 09:30

1 Answers1

3

First import the text file.

 import dir from './dir.txt';

then you can fetch and transform it into text:

fetch(dir)
  .then(row => row.text())
  .then(text => {
    console.log('text:', text);
  });
Yasin Br
  • 1,675
  • 1
  • 6
  • 16