I been given the a text file, and I want to convert it to an associative array so I can use a plugin and to convert the data into a table. The smartest way to do this I believe is to make it into an assoc. array, but everything i been trying gets me nowhere. Originally the file only have the IDs, not the names and yes I could manually erase the names and just used the numbers but it just seems counterproductive.
Here is the text file users.txt
Person_1 USERID_1
Person_2 USERID_2
Person_3 USERID_3
Person_4 USERID_4
Person_5 USERID_5
Person_6 USERID_6
Person_7 USERID_7
Person_8 USERID_8
Person_9 USERID_9
Person_10 USERID_10
Here is how my code was to read the original file that just had the numbers, users.js
$(document).ready( function() {
var userArray = [];
$.get('../users.txt', function(data){
userArray = data.split('\n');
console.log(userArray);
var barChartData = {
labels : ["User 1","User 2","User 3","User 4","User 5","User 6","User 7","User 8","User 9","User 10"],
datasets : [
{
label: "Number of CD's Bought",
fillColor : "rgba(0,0,0,0.5)",
strokeColor : "rgba(0,0,0,0.8)",
highlightFill: "rgba(222,222,222,0.75)",
highlightStroke: "rgba(222,222,222,1)",
data : [userArray[0],userArray[1],userArray[2],userArray[3],userArray[4],userArray[5],userArray[6],userArray[7],userArray[8],userArray[9]]
}
]
};
How can I update my code so I can have User[0][0]
to be Person_1
and User[0][1]
to be USERID_1
and so on for the other. I tried to replace the newline \n
but it only does it in the first line and the remaining newlines are ↵
in the console. Any ideas?
Just as note I originally get and XML file from a Query as A Web Service but that one has been even more troublesome