[英]How to print each element of an array in new line in txt file using javascript?
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 我看到out.txt为
item1, item2, item3, item4, item5, item6, item7,item8
How do I print them as? 如何将它们打印为?
item1
item2
item3
item4
item5
item6
item7
item8
Try to use the join()
to add the new lines : 尝试使用join()
添加新行:
fs.writeFile('out.txt',
uniqueMatches.join('\n'),
function (err) { console.log('Extract saved successful'); }
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.