Looking to convert a row from a csv file into an array and then transform the numeric values from string format.
This represents my csv file row:
const row = "TEXT,2020-06-04 06:16:34.479 UTC,179,0.629323";
My objective is to create this array (with the last two values in number format):
["TEXT","2020-06-04 06:16:34.479 UTC",179,0.629323]
I attempted this in three different ways, but did not achieve the desired outcome.
Attempt 1:
const array1 = row.split(",");
Outcome:
["TEXT","2020-06-04 06:16:34.479 UTC","179","0.629323"]
Attempt 2:
const array2 = row.split(",");
for (let element in array3){
array3[element] = +array3[element];
}
Outcome:
[null,null,179,0.629323]
Attempt 3:
const array3 = row.split(",").map(x=>+x);
Outcome:
[null,null,179,0.629323]
Any assistance would be greatly appreciated!
Thank you!