JavaScript string newline character?

后端 未结 15 1933
终归单人心
终归单人心 2020-11-22 08:06

Is \\n the universal newline character sequence in Javascript for all platforms? If not, how do I determine the character for the current environment?

I

15条回答
  •  攒了一身酷
    2020-11-22 08:36

    A practical observation... In my NodeJS script I have the following function:

    function writeToLogFile (message) {
        fs.appendFile('myserverlog.txt', Date() + " " + message + "\r\n", function (err) {
            if (err) throw err;
        });
    }
    

    First I had only "\n" but I noticed that when I open the log file in Notepad, it shows all entries on the same line. Notepad++ on the other hand shows the entries each on their own line. After changing the code to "\r\n", even Notepad shows every entry on its own line.

提交回复
热议问题