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 152 views
1 answer 163 views
1 answer 150 views
1 answer 141 views
2 answers 183 views
183 views asked May 30, 2023 by avibootz
1 answer 162 views
162 views asked May 30, 2023 by avibootz
...