Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Within Node, how do I split a string using newline (' ') ? I have a simple string like var a = "test.js again.js" and I need to get ["test.js", "again.js"]. I tried

a.split("
");
a.split("\n");
a.split("
");
a.split("
");

but the above doesn't work.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
456 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

> "a
b
c".split(/
?
/)
[ 'a', 'b', 'c' ]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...