I've tried using fetch, but when I print out the variable, it displays undefined. For example
var names; fetch('firstnames.txt') .then(response => response.text()) .then((data) => { names = data; }) console.log(names);