-2

What I need to be able to do is a to identify every row in a textfield or a text-file. So I can print any single row I want. For example push every row into an array (like this [row1][row2][row3]). I have no idea how to do this or if it's even possible. If it is i would appriciate some guidance, if it's not possible is there any other solution for my problem? Thank you!

WilliamG
  • 451
  • 1
  • 8
  • 16

1 Answers1

1

Try to use the .split() function. A simple example might be like this:

$(document).ready(function(){
 rows = $(".my-txt-area").val().split("\n");
 
 console.log("row 1: " + rows[0]);
 console.log("row 2: " + rows[1]);
 console.log("row 3: " + rows[2]);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea class="my-txt-area" style="width: 100%; height: 200px;">
Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation...
</textarea>
tgogos
  • 23,218
  • 20
  • 96
  • 128
  • Thank you for your answer, this is pretty much what i came up with, with help of the answer above. Still great explenation and i appricate the answer! – WilliamG Dec 01 '16 at 09:28