This function converts a list to an array when list has quotes and embedded comma:array function convertRow(required string lstRow) {    var arResult = [];    var arTemp = ListToArray(arguments.lstRow, ',', true);    var quoteMode = false;    var startQuote = false;    for (var i in arTemp) {        if (i CONTAINS '' && not quoteMode) { startQuote =  true; }        if (startQuote) {            ArrayAppend(arResult, replace(i, '', ''));            startQuote = false;            quoteMode = true;        }        else if (quoteMode) {            arResult[ArrayLen(arResult)] &= , & replace(i, '', '');            if (i CONTAINS '') quoteMode = false;        }        else            ArrayAppend(arResult, i);    }    writedump(lstRow);    writedump(arResult);    return arResult;}
Converting a list to an array when list has quotes and embedded comma
javascript;array;coldfusion
I could get rid of your startQuote variable, I reduced the number of i CONTAINS '' comparasions by 1.array function convertRow(required string lstRow) {    var arResult = [];    var arTemp = ListToArray(arguments.lstRow, ',', true);    var quoteMode = false;    for (var i in arTemp) {        var containsQuote = i CONTAINS '';        if (containsQuote && not quoteMode) {            ArrayAppend(arResult, replace(i, '', ''));            quoteMode = true;        }        else if (quoteMode){            arResult[ArrayLen(arResult)] &= , & replace(i, '', '');            quoteMode = not containsQuote;        }        else{            ArrayAppend(arResult, i);        }    }    writedump(lstRow);    writedump(arResult);    return arResult;}