3

My result set is an array that returns from a function.

['item1','item2','item3','item4','item5','item6','item7','item8']

I am writing it into a file using

fs.writeFile('out.txt', uniqueMatches, (err)=>{
     if(err) throw err;
          console.log('Extract saved successful');
});

I see the out.txt as

item1, item2, item3, item4, item5, item6, item7,item8

How do I print them as?

item1
item2
item3
item4
item5
item6
item7
item8
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Azim Shaik
  • 181
  • 1
  • 5
  • 14

2 Answers2

3

Try to use the join() to add the new lines :

fs.writeFile('out.txt',
    uniqueMatches.join('\n'),
    function (err) { console.log('Extract saved successful'); }
);
Azim Shaik
  • 181
  • 1
  • 5
  • 14
Zakaria Acharki
  • 66,747
  • 15
  • 75
  • 101
1

Use .join to add a line break to your data array that is to be written:

fs.writeFile('out.txt', uniqueMatches.join('\n');, (err)=>{
            if(err) throw err;
            console.log('Extract saved successful');
        });
petey
  • 16,914
  • 6
  • 65
  • 97