I am trying to concatenate strings in Node.js . I started with a very basic example, I am trying to read a file, and simply concatenate all the lines one by one to a new object, but from some reason when I do console.log, only the last line appears. Its like each new line runs over the other.
here is the code
fs.readFile("C:/example.srt", function(error, data) {
if (error) { throw error; }else {
var newData = "";
data.toString().split("\n").forEach(function (line) {
newData = newData + line;
});
console.log(newData);
}
});
data.toString().split("\n").lengthat line 4?