// Example data as an array of objects
const data = [
{ name: 'John', age: 30, city: 'New York' },
{ name: 'Alice', age: 25, city: 'San Francisco' },
{ name: 'Bob', age: 35, city: 'Los Angeles' }
];
// Convert array of objects to CSV format
const csvContent = data.map(obj => Object.values(obj).join(',')).join('\\n');
// Log the generated CSV content to the console
console.log('CSV Content:', csvContent);
code
Convert Array of Objects to CSV
This JavaScript code demonstrates how to convert an array of objects (data) into CSV format. It uses the map and join functions to transform and concatenate the data, and the result is logged to the console.
Console.log
CSV
Array of Objects
Data Transformation