Skip to content
Advertisement

How to add a column to 1d json array and save it to a file?

CONTEXT

I am trying to save an array to a text file.

My array is a js variable arrR (say):

[-0, 0.0016, 0.0034, 0.005, 0.0067, 0.0082, 0.0103, 0.0116, 0.0135, 0.0154, 0.017]

The function below saves the array in a text file:

JavaScript

And this works nicely.

WHAT I WOULD LIKE TO DO

Instead of having a .txt file like:

[-0, 0.0016, 0.0034, 0.005, 0.0067, 0.0082, 0.0103, 0.0116, 0.0135, 0.0154, 0.017]

I would like to have a .txt or a.csv file, which would like:

JavaScript

where:

the second column of the file is arrR,

the first column is an array where all elements are 0,3,6 (the difference being diff) ,

the header is the current time.

Is there a simple way to do it ?

Many thanks

Advertisement

Answer

You could change the

JavaScript

to

JavaScript
Advertisement