RelativPerspektivR
Reactiflux4y ago
6 replies
RelativPerspektiv

✅ – BIOLOGY SCIENCE – 11-02 Jul 28

this is my code
const fs = require('fs');
const x = [1, 2, 3 ...]; // array consisting of numbers
const temp = []; // empty array

x.forEach((item) =>
{
  fx(item).then((promiseData) =>
  {  // fx is a function returning a promise

    fs.writeFileSync('path/to.file', promiseData);

    if ( (item / 2).toString().includes('.') ) {
      temp.push(item);
    }

  });
});

fs.writeFileSync('path/to/differnet.file', JSON.stringify(temp, null, 4));

for some reason the content of
path/to/different.file
is just an empty array
i have tried logging the
temp
array after the
forEach
loop, it is not empty, but when i try to write the file, it doesnt work properly
any fixes ?
Was this page helpful?