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

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? Commented Mar 19, 2022 at 18:11
  • stackoverflow.com/questions/50539756/… Commented Mar 19, 2022 at 18:11
  • By "items" do you mean things on separate lines? Commented Mar 19, 2022 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. Commented Mar 19, 2022 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. Commented Mar 20, 2022 at 9:30

1 Answer 1

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);
  });
Sign up to request clarification or add additional context in comments.

2 Comments

This works, but how do I keep the text in an let outside of the fetch brackets?
@ButaCoder Check this out.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.