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?
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;
}
link to spreadsheet: https://docs.google.com/spreadsheet/ccc?key=0AjA1J4T5598RdGRWd0p4Q3FtaW5QTG1MVVdEVUQ0NFE#gid=0