function syncText() {
var xhr = new XMLHttpRequest();
xhr.open("get", "data/contacts.txt", false);
xhr.send(null);
if (xhr.status == 200) {
var data = xhr.responseText;
var items = data.split("|");
items.sort();
var div = document.getElementById("header2");
for (var i = 0; i < items.length; i++) {
var p = document.createElement("p");
var text = document.createTextNode(items[i]);
p.appendChild(text);
div.appendChild(p);
}
} else {
alert("data retrieval failed...");
}
}
Actually your lines var items = data.split("|"); and items.sort(); mix all without distinguishing the mail of kate and the pseudo of jessica ! It makes no sense to try to classify all different fields !
You have at first to build an array with the different lines.
Then you will be able to split in a loop the seven items : pseudo, sex, name, date, addres1, adress2, mail and store all this fields in an array of objects without edition...
Bookmarks