Search code examples
javascriptarraysdictionarymultidimensional-arrayhashmap

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("\r\n");

    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"

Solution

  • Add this code:

    for(let i = 0; i < splitString.length; i++){
    splitString[i] = splitString[i].split(",")
    }