JavaScript Platform Independent Line分隔符 [英] JavaScript Platform Independent Line separator
问题描述
JavaScript中是否存在类似于Java的 System.getProperty(line.separator);
的内容?
Does something similar to Java's System.getProperty("line.separator");
exist in JavaScript?
编辑:我使用的是非浏览器JavaScript环境Node.js
I am using the non-browser JavaScript environment Node.js
推荐答案
我遇到了同样的问题并遇到了这个相当古老的问题。投资一段时间后,我终于在 os.EOL rel =noreferrer> os 文档。
I had the same problem and came across this quite old question. After investing for some time I finally found os.EOL
at the very end of the os documentation.
var os = require('os')
console.log(JSON.stringify(os.EOL)) // prints "\n" on my Mac
JSON.stringify
在这种情况下很重要,否则你只会在控制台中看到一个空白行(这是有道理的,因为它应该做什么)。在正常使用情况下,不需要它。
JSON.stringify
is in this case important, otherwise you would only see a blank line in the console (which makes sense because that's what it should do). In an normal use case it is not needed.
这篇关于JavaScript Platform Independent Line分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!