Answers for "Working with CSV in JavaScript"

1

Working with CSV in JavaScript

/*
    This code comes from Vincent Lab
    And it has a video version linked here: https://www.youtube.com/watch?v=95wAbrQAm5g
*/

// Import dependencies
const fs = require("fs");
const csv = require("csvtojson");
const { Parser } = require("json2csv");

(async () => {

    // Load the cars
    const cars = await csv().fromFile("cars.csv");

    // Show the cars
    console.log(cars);

    // Modify the cars
    cars[0].Year = 1998;

    // Saved the cars
    const carsInCsv = new Parser({ fields: ["Year", "Make", "Model", "Length"] }).parse(cars);
    fs.writeFileSync("cars.csv", carsInCsv);

})();
Posted by: Guest on April-20-2021

Code answers related to "Working with CSV in JavaScript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language