Splitting a string twice [closed]

1 day ago 4
ARTICLE AD BOX

Okay so let's switch this around so that you are getting a more full picture

//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();

Textfile

Name1 Number1 Role1 Company1, Name2 Number2 Role2 Company2

this is what im dealing with i don't seem to be able to setup a new variable with all values filled and gets instead a array that is just a bunch of strings.

Read Entire Article