With all of the updates to JavaScript in the last few years, is there a way to read a text file into a string with one line of code?
Something like:
var data = await fetch(url).data;
With all of the updates to JavaScript in the last few years, is there a way to read a text file into a string with one line of code?
Something like:
var data = await fetch(url).data;
2
Answers
You have to call
response.text()
to get the contents returned fromfetch()
.It seems you mean "local file" because you mentioned "file" and "read".
It has always been one line excluding import.