const items = [
{name: 'John', age: 31},
{name: 'Maria', age: 25},
];
const replacer = (key, value) => value === null ? '' : value // specify how you want to handle null values here
const header = Object.keys(items[0]);
let csv = items.map(row => header.map(fieldName => row[fieldName], replacer).join(','));
csv.unshift(header.join(','));
csv = csv.join('
');
console.log(csv)