dsv.formatRows(rows)
Formats the specified array of array of string rows as delimiter-separated values, returning a string. This operation is the reverse of dsv.parseRows. Each row will be separated by a newline (\n
), and each column within each row will be separated by the delimiter (such as a comma, ,
). Values that contain either the delimiter, a double-quote (") or a newline will be escaped using double-quotes.
To convert an array of objects to an array of arrays while explicitly specifying the columns, use array.map. For example:
var string = d3.csvFormatRows(data.map(function(d, i) { return [ d.year.getFullYear(), // Assuming d.year is a Date object. d.make, d.model, d.length ]; }));
If you like, you can also array.concat this result with an array of column names to generate the first row:
var string = d3.csvFormatRows([[ "year", "make", "model", "length" ]].concat(data.map(function(d, i) { return [ d.year.getFullYear(), // Assuming d.year is a Date object. d.make, d.model, d.length ]; })));
Please login to continue.