-1

My array,

var array = [[{'text':'alk'},{'text':'ank'}],[{'text':'nmk'},{'text':'jlk'}],[{'text':'mml'},{'text':'hhj'}],[{'text':'nnl'}]]

I want to write all this data into file each array of array into one file.

   file 1 has [{'text':'alk'},{'text':'ank'}],[{'text':'nmk'},{'text':'jlk'} data 
   file 2 has {'text':'mml'},{'text':'hhj'}
   file 3 has {'text':'nnl'}

I wrote the code as,

arrays.forEach(function(i,v){
    v = v+1;
    var newData ='saved';
    fileName = 'public/amp/test2/amp-blogs-list-page'+v+'.html';
    i.forEach(function(k,l){
        filewrite goes here
    });
});

I see only the last item af each arry is written into the file,Can anyone please help me.Thanks.

K L P
  • 107
  • 6

1 Answers1

1

I think the problem is in the writing into the file. If you see only the last items of each arrays, this means that you rewrite your files every time. You just need to append every item not rewrite them.

For appending to file see here

Suren Srapyan
  • 66,568
  • 14
  • 114
  • 112