Skip to content
Advertisement

How to turn data from a txt file into an array of objects in Node

I’m new to Node, and I have a text file that has data like this

JavaScript

I would like to create an array of objects like this

JavaScript

How can I do this? This was my attempt:

JavaScript

But this create an array for each object and I get all the data showing under date like this:

JavaScript

Advertisement

Answer

You can try readline internal module, by the way (see this example), if your file is big and you do need line by line processing:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement