List to (JavaScript) Array

Convert a list of strings (separated by \n [new line]) into an array that you can paste into your code.

by ecropolis

HTML

<div>
  <form id="form-input">
      <button type="submit" style="background:#bada55; font-size: 14px; margin: 0 15px; padding: 4px 8px; color: #545454">CONVERT LIST TO ARRAY</button>
      <textarea id="input" style="height: 500px; width:95%; margin: 15px;"></textarea>
  </form>
</div>
<p style="text-align:right;">
<a href="https://ecropolis.com" target="_blank" style="font-size: 10px">ecropolis.com</a>
</p>

CSS

body {
    background: #cacaca;
}

JavaScript

var form = document.getElementById('form-input');

form.onsubmit = function(){
    var input = document.getElementById('input');
    var lines = input.value.split('\n');
    var a = 'var a = [';
    for(var i = 0;i < lines.length;i++){
        if(lines[i].length)
        	a += "'" + lines[i] + "', "
    }
    a = a.slice(0,-2) + '];'
    input.value = a;
    return false;
}