0

I´ve got a text field where users can type names (one by line). I´d like to get these values and put them in a array. The arrays starts off at empty. E.g list = [];

I tried to use the .push() and .join() methods

<div class="form">
       <label for="nomes">Insira um nome por linha</label><br>
       <textarea id="nomes"></textarea>

 </div>
 <button id="sortear">Sortear</button>


function SorteioApp() {
    var lista = [];
    var entradaDados = document.querySelector('#nomes').value;
    lista.push(entradaDados);


}
  • 1
    The value of the text area will be one string with multiple line breaks, so use `split` to break that into an array of strings, e.g. `var lista = entradaDados.split('\n');` – p.s.w.g May 28 '19 at 21:27
  • It worked, pal. Thank you! – Diego Freire May 28 '19 at 21:30
  • This is identical to this question https://stackoverflow.com/questions/2299604/javascript-convert-textarea-into-an-array – aggaton May 28 '19 at 21:45

0 Answers0