# generateCSV (deprecated)

{% hint style="danger" %}
`generateCSV` was deprecated in version **4.28.0** of the JourneyApps Container and replaced with [`CSV`](https://docs.journeyapps.com/reference/build/js-ts-apis/csv).
{% endhint %}

{% hint style="info" %}
**Version compatibility**

`generateCSV` was introduced in version **4.25.0** of the JourneyApps Container.
{% endhint %}

### Format

```javascript
generateCSV(source, options);
```

| Parameter            | Details                                                                                                                                                                                                                   |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `source`             | <p>One of:<br></p><ul><li>Array</li><li>Matrix (array of arrays)</li></ul>                                                                                                                                                |
| `options` (Optional) | <p>Object with the following properties:<br></p><ul><li><code>heading</code>: Array of column headings</li><li><code>delimiter</code>: Character to separate columns with.</li></ul><p><br>Defaults to <code>,</code></p> |

Returns: the generated CSV as a **string**.

### Examples

{% code title="main.js" %}

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

{% endcode %}

In this case, `csv_file` is:

{% code title="csv\_file.csv" %}

```
Type,Color
Cell Phone,Black
Computer,Red
```

{% endcode %}

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:

{% code title="main.js" %}

```javascript
var allAssets = DB.asset.all().toArray();

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

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

{% endcode %}
