I have a csv file generated by a database that I need to convert into an array. The file is in the same folder as my script.
Here is how the csv file is formatted: (I am unable to show the original data)
https://i.sstatic.net/SgKt1.png
https://i.sstatic.net/PxiYW.png
I came across a d3 script that helps me import data from the csv file. This is what my code looks like:
var myArray= []
d3.csv("data.csv", function(data){
myArray.push(data)
});
console.log(myArray)
Now, I can view the array in the console by using the command "myArray". It looks like this:
https://i.sstatic.net/ZA7Tw.png
https://i.sstatic.net/usHGL.png
When I inspect the array, I see multiple objects structured like this:
0: { "HeaderA": "A1", "HeaderB": "B1", "HeaderC": "C1", … }
1: { "HeaderA": "A2", "HeaderB": "B2", "HeaderC": "C2", … }
2: { "HeaderA": "A3", "HeaderB": "B3", "HeaderC": "C3", … }
and so forth...
My issues:
When I type
myArray[0]
in console, I see the first object but cannot access its elements (A1,B1,C1...). Why? How?I encounter an error when trying to use
myArray[0]
in my code to loop through the objects: "ReferenceError: array is not defined"I am aiming to structure the array like this...
[["HeaderA", "A1", "A2", "A3", "A4" "A5"], ["HeaderB", "B1", "B2", "B3", "B4" "B5"],["HeaderC", "C1", "C2", "C3", "C4" "C5"],...]
...in order to effectively work with the data. However, I am unsure how to achieve this since I cannot access individual elements?
Thank You :)