Skip to content
Advertisement

Convert Array in Map or 2D Array

So I basically have a gradebook that is a .csv file and is formatted like this

name, grade name, grade

I am looking for the best way to split my array so that I can access each independently but they are still related to each other.

function handleFileLoad(event){
    var baseText = event.target.result;
    var splitString = baseText.split("rn");

    console.log(splitString)
}

This is my current code so it currently splits the original text into the array properly but the output is like this

0: "Name,Percent"
​
1: "Eddie,65.95"
​
2: "Alice,56.98"
​
3: "Delmar  ,96.1"
​
4: "Edmund  ,78.62"

when I want it like

0: "Name" "Percent"
​
1: "Eddie" "65.95"
​
2: "Alice" "56.98"
​
3: "Delmar" "96.1"

4: "Edmund" "78.62"

Advertisement

Answer

Add this code:

for(let i = 0; i < splitString.length; i++){
splitString[i] = splitString[i].split(",")
}
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement