[removed] Convert textarea into an array

后端 未结 6 1716
萌比男神i
萌比男神i 2020-12-08 13:44

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...

6条回答
  •  醉梦人生
    2020-12-08 14:20

    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

提交回复
热议问题