Intenté usar fetch, pero cuando imprimo la variable, se muestra indefinida. Por ejemplo
var names; fetch('firstnames.txt') .then(response => response.text()) .then((data) => { names = data; }) console.log(names);