generateCSV (deprecated)

generateCSV was deprecated in version 4.28.0 of the JourneyApps Container and replaced with CSV.

Version compatibility

generateCSV was introduced in version 4.25.0 of the JourneyApps Container.

Format

generateCSV(source, options);
Parameter
Details

source

One of:

  • Array

  • Matrix (array of arrays)

options (Optional)

Object with the following properties:

  • heading: Array of column headings

  • delimiter: Character to separate columns with.

Defaults to ,

Returns: the generated CSV as a string.

Examples

main.js
var mx = [['Cell Phone', 'Black'], ['Computer','Red']];
var csv_file.csv = generateCSV(mx, { heading: ['Type', 'Color'] } );

In this case, csv_file is:

csv_file.csv
Type,Color
Cell Phone,Black
Computer,Red

Suppose we have an asset data model object with (amongst others) name and cost as fields, and we want to generate CSV for all assets and their names and costs:

main.js
var allAssets = DB.asset.all().toArray();

var myMx = allAssets.map(function(asset) {
    return [asset.name, asset.cost];
});

var csv = generateCSV(myMx, {heading: ['Name', 'Cost']});

Last updated