Answers for "textarea split on newline"

0

textarea split on newline

$(function(){
    var lines = [];
    $.each($('#data').val().split(/\n/), function(i, line){
        if(line){
            lines.push(line);
        } else {
            lines.push("");
        }
    });
    console.log(lines);
});
Posted by: Guest on December-01-2020
0

textarea split on newline

<script>
$(function(){
    var lines = [];
    $.each($('#data').val().split(/\n/), function(i, line){
        if(line){
            lines.push(line);
        }
    });
    console.log(lines);
});
</script>


<textarea id="data">
I like to eat icecream. Dogs are fast.

The previous line is composed by spaces only.



The last 3 lines are empty.

One last line.
</textarea>
Posted by: Guest on December-01-2020

Browse Popular Code Answers by Language