I would like help in reformatting the output returned from promise.all, it is returned as an Array of objects but I would like to convert to a string of values only, with the results strung together with one space in between each result.
Current output
[
{ yesnon: 'non' },
{ yesnon: 'yes' },
{ yesnon: 'yes' },
{ yesnon: 'yes' },
{ yesnon: 'yes' },
{ yesnon: 'yes' },
{ yesnon: 'yes' },
{ yesnon: 'yes' }
]
Goal Output: (A one line string with spaces between results, remove "yesnon:")
non yes yes
The code
const fs = require('fs');
const readline = require('readline')
var mynumtosearch = 56700;
var searchfile = 35;
const p1 = new Promise((resolve, reject) => {
let lineCount = 0;
let v=0;
let yesnon = "non";
let readStream = readline.createInterface({
input: fs.createReadStream('PATH TO MY FILE','utf8')
});
readStream.on("line", (line) => {
lineCount++;
// console.log(line)
if(line==mynumtosearch)
{
yesnon="yes";
console.log("I am here");
v++;
}
});
readStream.on("close", () =>
resolve({
yesnon
})
)
});
const p2 = new Promise((resolve, reject) => {
let readStream = readline.createInterface({
input: fs.createReadStream('PATH TO MY FILE','utf8')
});
let lineCount = 0; let v=0;
let yesnon = "non";
readStream.on("line", (line) => {
lineCount++;
// console.log(line)
if(line==mynumtosearch)
{
yesnon="yes";
console.log("I am here");
v++;
}
});
readStream.on("close", () =>
resolve({
yesnon
}) )
});
const p3 = new Promise((resolve, reject) => {
let lineCount = 0; let v=0;
let yesnon = "non";
let readStream = readline.createInterface({
input: fs.createReadStream('PATH TO MY FILE','utf8')
});
readStream.on("line", (line) => {
lineCount++;
//console.log(line)
if(line==mynumtosearch)
{
yesnon="yes";
console.log("I am here");
v++;
}
});
readStream.on("close", () =>
resolve({
yesnon
}) )
});
console.log(h);
Promise.all([p1, p2, p3]).then((results) => {console.log(results);
});