1

Im working with a lot of datas which i turned into arrays , for simplicity lets assume i have array that looks like this

["dataone:dataone","datatwo:datatwo","datathree:datathree"]

im writting output to the file using fs.writeFile

but the output is always in the same row e.g dataone:dataone","datatwo:datatwo","datathree:datathree

i would like to output to be like with "\n" e.g

dataone:dataone
datatwo:datatwo
datathree:datathree

is it possible to make output in file look like this? im writting in into .txt file

2

2 Answers 2

1

Join the data with line breaks before writing to file

var os = require('os');
var brk = os.platform().substring(0,3).toLowerCasee() === 'win'
    ? '\r\n' : '\n';

var data = ["dataone:dataone","datatwo:datatwo","datathree:datathree"]
fs.writeFile(filename, data.join(brk), {encoding : 'utf8'},  function (e) {
   // etc  
});
Sign up to request clarification or add additional context in comments.

Comments

1

You can join your array with \n before writing it to the file:

var arr = ["dataone:dataone","datatwo:datatwo","datathree:datathree"]
var arr2 = arr.join('\n');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.