Код: Выделить всё
//this fetches the textfile
function fetchTextFile()
{
fetch("../TxtDatabase/Contactpage.txt")
.then(response => response.text())
.then(data => parseData(data))
}
//this parses the data
function parseData(data){
//first split
let dataArray = data.split(",");
let contactDataArray = []
let contacts = []
for(let i = 0; i < dataArray.length; i++){
//second split
contactDataArray.push(dataArray[i].split("\n"));
//add contact
contactsArray.push(new Contact(contactDataArray[0],contactDataArray[1], contactDataArray[2], contactDataArray[3]))
}
//this gives contacts[0] = full first string, contact[1] second full string not a new class (contact) with all its data filled
Console.log(contacts)
}
fetchTextFile();
Код: Выделить всё
Name1
Number1
Role1
Company1,
Name2
Number2
Role2
Company2
Подробнее здесь: https://stackoverflow.com/questions/798 ... ring-twice
Мобильная версия