Question

How would you go about breaking up a textarea value into an array, based on the end of line separation? Use of jQuery is cool by me...

Was it helpful?

Solution

This should work (tested in Firefox and Google Chrome):

var arrayOfLines = $('#textAreaID').val().split('\n');

OTHER TIPS

var stringArray = document.getElementById('textarea').value.split('\n');

Cross-platform way:

var area = document.getElementById("area");             
var lines = area.value.replace(/\r\n/g,"\n").split("\n");

You could try this function :

function textToArray(){
  var someArray = [];    
  var nameList = $("#txtArea").val();

  $.each(nameList.split(/\n/), function (i, name) {     

      // empty string check
      if(name != ""){

          someArray.push(name);

      }        
});

taken from : CONVERT TEXTAREA CONTENT TO AN ARRAY USING JQUERY

This method worked well:

var textArea = document.getElementById("textAreaId");
var arrayFromTextArea = textArea.value.split(String.fromCharCode(10));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top