I am trying to edit a single element in an array built by fast-csv in Node.JS.
Fast-csv is editing all the columns when a single array index is included, and no array indexes when a 2D array index is used.
The question is, is it possible to edit a single element from a CSV in javascript?
Input (input.csv):
hello,1,'1',forty-two,
yellow,brown,red,orange
Current output:
[ 'hello', '1', 696, 'forty-two', '' ]
[ 'yellow', 'brown', 696, 'orange' ]
Target output:
[ 'hello', 'julian', 696, 'forty-two', '' ]
[ 'yellow', 'brown', 696, 'orange' ]
Logic:
var fs = require('fs');
var csv = require('fast-csv');
fs.createReadStream('./IOinput/input.csv')
.pipe(csv())
.on('data', function(data){
//console.log(data);
data[0][1] = 'julian';
data[2] = 696;
console.log(data);
})
.on('end', function(data){
console.log('Read finished');
})
Dependencies:
npm install fast-csv
data[2] = 696works so why don't you trydata[1] = 'julian'instead ofdata[0][1]