[Javascript] How can I count the number of lines present in a given string?
I want to count the number of lines present in a given string. How can I do that in Javascript?
1 Answer
3 years ago by Jahaan
You can count the number of lines by splitting the string with linebreak. Split converts the given string into array of substrings and then by using .length
which gives you the count of number of lines present in the given string.
string.split(/\r\n|\r|\n/).length
3 years ago by Meera