In my current C#
code, I used the .NET
package File.ReadLines()
. Are there any ways to re-write that code in Javascript?
var csvArray = File.ReadLines(filePath).Select(x => x.Split(',')).ToArray();
I know that LINQ Select
could be used in Javascript. My current progress is on reading a CSV
file. Kindly check my JS code below.
var fs = require('fs');
var csv = require('fast-csv');
var filepath = $('#appFilePathInput').value();
fs.createReadStream(filepath)
.pipe(csv())
.on('data', function(data){
//Should I put the LINQ Select and Split toArray code here?
});
.on('data', function(data){
console.log('Read Finished');
});
GOAL is to read the local CSV file to an Array
in JavaScript
.
Kindly help me improve my existing code
since it is my first time writing code in pure Javascript.
Thank you very much!
Copyright Notice:Content Author:「JPaulPunzalan」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/43107658/equivalent-of-file-readlinesfilepath-c-sharp-in-javascript