Tengo una matriz de muestra de estructuras como esta
var array = [ {item1: 'john', item2: 'micheal'}, {item1: 'joe', item2: 'mich'}, {item1: 'jo', item2: 'mi'}, ]Trato de analizar todos estos objetos (900 objetos en esta matriz) en otro archivo usando este código
const fs = require('fs'); const writeStream = fs.createWriteStream('file.txt'); const pathName = writeStream.path; // write each value of the array on the file breaking line array.forEach(value => writeStream.write(`${value}\n`)); // the finish event is emitted when all data has been flushed from the stream writeStream.on('finish', () => { console.log(`wrote all the array data to file ${pathName}`); }); // handle the errors on the write process writeStream.on('error', (err) => { console.error(`There is an error writing the file ${pathName} => ${err}`) }); // close the stream writeStream.end();Sin embargo, cuando abro el archivo obtengo
[object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object] [object Object]que no es lo que quiero. quiero ver
{item1: 'john', item2: 'micheal'}, {item1: 'joe', item2: 'mich'}, {item1: 'jo', item2: 'mi'},que no es lo que veo. ¿Cómo puedo corregir esto?