Total Pageviews

2018/07/12

[JavaScript] How to convert textarea into an array?

Problem
I have a textarea as bellows:
   <textarea class='form-control' id='sentencesToLabeledData' name='sentencesToLabeledData' rows='10' cols='50'> </textarea>

I would like to get its value and convert into an array. How to do it?

How-To
Here has two steps to fulfill this requirement:
   // Step 1. get the value of textarea
   var sentencesToLabeledData = document.getElementById("sentencesToLabeledData").value;
   // Step 2. split the value of textarea by \n, then it will convert into an array
   var sentenceArray = sentencesToLabeledData.split('\n');



No comments: