How to count the number of lines from a string in JavaScript

1 Answer

0 votes
const s = "line1\nline2\nline3\nline4\nlin5\nline6";

console.log(s.split(/\r\n|\r|\n/).length);

  
    
    
    
/*
run:
    
6
    
*/

 



answered Aug 19, 2021 by avibootz

Related questions

1 answer 149 views
1 answer 180 views
2 answers 198 views
1 answer 144 views
1 answer 151 views
1 answer 155 views
1 answer 245 views
...