How in node to split string by newline ('\n')?

后端 未结 7 1866
南笙
南笙 2020-11-29 17:30

How in node to split string by newline (\'\\n\') ? I have simple string like var a = \"test.js\\nagain.js\" and I need to get [\"test.js\", \"again.js\"]<

7条回答
  •  独厮守ぢ
    2020-11-29 18:19

    Try splitting on a regex like /\r?\n/ to be usable by both Windows and UNIX systems.

    > "a\nb\r\nc".split(/\r?\n/)
    [ 'a', 'b', 'c' ]
    

提交回复
热议问题