• Parse a CSV string into a 2D array of rows and columns. Every row is returned, including the first one, so a header row appears as row 0. Numeric values are converted to numbers unless disableNumberConversion is true. Returns null when the text cannot be parsed.

    Use this for CSV text the script already holds (for example from an attribute value or a file's content). To read a CSV file from Global Data, use getGlobalFileCsvContent instead.

    Parameters

    • csv: string

      The CSV text to parse

    • Optional hasHeaders: boolean

      Currently ignored; the first row is always returned as data

    • Optional delimiter: string

      Field delimiter; only the first character is used (default: ",")

    • Optional quote: string

      Quote character; only the first character is used (default: '"')

    • Optional disableNumberConversion: boolean

      When true, every value is returned as a string (default: false)

    Returns (string | number)[][] | null

    2D array of rows and columns, or null if the CSV could not be parsed

    Example

    var rows = parseCsv("Size,Price\nA4,1.50\nA3,2.75", true, ",", "\"", false);
    if (rows) {
    // skip the header row
    for (var i = 1; i < rows.length; i++) {
    if (rows[i][0] === Item.getAttributeValue("Size")) {
    return rows[i][1] * Item.Quantity;
    }
    }
    }

    Example

    // Semicolon-separated values, keeping codes such as "007" as strings
    var codes = parseCsv("Code;Name\n007;Gold", true, ";", "\"", true);

Generated using TypeDoc