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 142 views
1 answer 175 views
2 answers 191 views
1 answer 137 views
1 answer 146 views
1 answer 148 views
1 answer 235 views
...