title: Google Spreadsheet Split Based on newline
body: <p>I am trying to split a cell that has multiple values delimited by a new line, it works perfectly for cells that have more than 1 value, but if I get a cell with just 1 value (ie, no newline character it errors out) how can I solve this?</p>
  
  <pre><code>function splitColumnAndRepeatRows(anArray, splitColumnIndex) 
  {
  var output = [];
  for (i in anArray)
  { // for each row
  var splitArray = anArray[i][splitColumnIndex].split("\n"); // split values in specified column
  for (j in splitArray)
   { // for each split cell value
    if(splitArray[j]=="")
      continue;
    var row = anArray[i].slice(0); // take a copy of source row 
    //row[splitColumnIndex] = alltrim(splitArray[j]); // replace comma separated value with current split value
    row[splitColumnIndex] =splitArray[j];
     output.push(row); // push new row to output
   }
  } 
  return output;
  }
  </code></pre>
  
  <p>link to spreadsheet: <a href="https://docs.google.com/spreadsheet/ccc?key=0AjA1J4T5598RdGRWd0p4Q3FtaW5QTG1MVVdEVUQ0NFE#gid=0" rel="noreferrer">https://docs.google.com/spreadsheet/ccc?key=0AjA1J4T5598RdGRWd0p4Q3FtaW5QTG1MVVdEVUQ0NFE#gid=0</a></p>