I have a webpage that displays last 1000
lines of a logfile then updates via AJAX every x
seconds loading new content (if any) and appending to textare
You should be able to use a single split
and then join
after truncating the data, something like this:
// on data retrieved
var total = ((textarea.value
? textarea.value + "\n"
: "")
+ new_data).split("\n");
if (total.length > 10)
total = total.slice(total.length - 10);
textarea.value = total.join("\n");
Working example: http://jsfiddle.net/ArvQ7/ (cut to 10 lines for brevity)