// 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);Convert Array of Objects to CSV
javascript
Related Posts
More content you might like
Tutorial
javascript
Running JavaScript in the Browser Console
- Arrow keys: Navigate through previous commands.
Shift+Enter: Write multi-line code.
- The console displays detailed error messages to help debug code.
Dec 10, 2024
Read More Tutorial
javascript
Mastering console.log Advanced Usages and Techniques
console.time('loop');
for (let i = 0; i < 1000000; i++) {
// Some operation
}
console.timeEnd('loop'); // Output: loop: <time in ms>console.count keeps track of how many times it has been called with a particular label, which can be useful for debugging loops or recursive functions.
Sep 02, 2024
Read More Tutorial
mysql
Data Import and Export in MySQL
LOAD DATA INFILE '/path/to/data.csv'
INTO TABLE your_table_name
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;/path/to/data.csv: The path to the CSV file.your_table_name: The table into which the data will be imported.FIELDS TERMINATED BY ',': Specifies the field delimiter.ENCLOSED BY '"': Specifies the field enclosure character (if any).LINES TERMINATED BY '\n': Specifies the line terminator.IGNORE 1 LINES: Ignores the header line in the CSV file (if present).
Aug 12, 2024
Read More Code
javascript
Parse JSON String to Object
No preview available for this content.
Jan 26, 2024
Read MoreDiscussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!