How to split a string by newline in Node.js

1 Answer

0 votes
const str = "NodeJS\nPython\n\r\nC++\nC";

const arr = str.split(/\r?\n/).filter(element => element);
 
console.log(arr);
 
 
 

 
/*
run:
 
[ 'NodeJS', 'Python', 'C++', 'C' ]

*/

 



answered May 1, 2022 by avibootz

Related questions

1 answer 144 views
1 answer 153 views
1 answer 138 views
1 answer 134 views
2 answers 174 views
174 views asked May 30, 2023 by avibootz
1 answer 153 views
153 views asked May 30, 2023 by avibootz
...