Counting number of lines in the string in Javascript is able to implement by regular expression.

var lines = data.match(/^/gm).length+1;