This function is quite quick and efficient in counting and returning the number of linebreaks in a string:
var countLinebreaks = function(str){ return str.split(/\n|\f/).length; }