I am trying store data in a .txt file, and then convert it back in to a Javascript list, or array, whatever you call it.
Data in txt file:
[{ firstName: "John", lastName: "Carpenter" },
{ firstName: "Dav", lastName: "Douglas" }]
Then I am trying to make it a list variable:
// my variable
var people = []
// read data from txt file
fs.readFile("./data/data.txt", "utf-8", (err, data) => {
if (err) { console.log(err) }
console.log(data, typeof(data));
people = data
})
Is there a way to convert it from a string to an array?