With JavaScript I am trying to pull a text file and turn it into a string. I got that working, but I want to turn that string into a array with commas or hyphens. Here's what I got so far to split the words into separate elements on a HTML page
function title() {
fetch('Text.txt')
.then(response => response.text())
.then(text => name = text)
.then(name => name.toUpperCase());
return(name);
};
function append(text, id) {
var p = document.createElement('P');
p.id = 'title' + id;
p.innerHTML = text;
document.getElementById('imgcont').appendChild(p);
};
function getName() {
name = title();
name.split("-");
append(name[0], 1);
append(name[1], 2);
};
The text file will include something like this
Fighers-Conro
I am trying to append this to 2 HTML Element, and I got that working just fine, but every time I look at the output I just get the letter "F" on the fist element and the letter "i" on the second element in the html page. I got further into it, and used console.log(Array.isArray(name));
and it returned False, but a self made array returns True.
I may be doing one small mistake, but I can't find the issue. Any help would be appreciated!