The problem is that I want to use the array elsewhere in my code. But I do not know how to access it? Is there any other way to read the file and turn it into an array that I can use?
var dir = 'file.txt';
function file() {
const fileUrl = dir;
fetch(fileUrl)
.then( response => response.text() )
.then( text => readFile(text) )
}
function readFile(text) {
var lines = text.split('\n');
var array = [];
var str;
for (var i = 0; i < lines.length; i++) {
var str = lines[i];
tmp = str.split(",");
array[i] = tmp;
}
}
file.txt
W,W,W,W,W,W,W,W,W
B,B,B,B,B,B,B,B,B
C,C,C,C,C,C,C,C,C
D,D,D,D,D,D,D,D,D