I have a filepath that leads to a .txt file that has a number of objects in it. I'm trying to write a JavaScript function that will take in this filepath as an argument and allow me to access and iterate over these objects, but everything I've tried and found online doesn't work. Is there a technique to accomplish this task?
I'm just trying to in vs code. The contents of the .txt file are:
{"food": "chocolate", "eaten", true}
{"food": "hamburger", "eaten", false}
{"food": "peanuts", "eaten", true}
{"food": "potato", "eaten", true}
I tried just iterating over the file path as an argument but that didn't work and it just returned the file path itself, and I have had no luck with any of the read file solutions on this site.
I know in Ruby this is easily accomplishable through:
File.open("my/file/path", "r") do |f|
f.each_line do |line|
puts line
end
end
But I am confused about the JavaScript solution.