Using javascript to fetch a txt content

If the txt filename is test.txt

fetch("test.txt").then(function(response){return response.text();}).then(function(text){console.log(text);});

Run it and console will show context of test.txt

It can be used in HTML page if you need to load something store in a txt file.

There's another way by using XHR, Axios or jQuery, but i like this, it's really easy and clean.