Add data read file from csv dataset
This commit is contained in:
parent
d2087fdc51
commit
e9911d6b3b
3
data/people.csv
Normal file
3
data/people.csv
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
id, name, age
|
||||||
|
1, Sambo Chea, 24
|
||||||
|
2, Ponlork Chea, 12
|
|
16
src/index.js
Normal file
16
src/index.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
const file = require('fs')
|
||||||
|
|
||||||
|
file.readFile('./data/people.csv', 'utf-8', (err, data) => {
|
||||||
|
if (err) {
|
||||||
|
console.error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(data)
|
||||||
|
|
||||||
|
const rows = data.split(/\r?\n/);
|
||||||
|
const header = rows[0].split(',').map(str => str.trim())
|
||||||
|
console.log(header)
|
||||||
|
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user