0

I have a text file with ID's like this:

111111111
222222222
333333333

And I need to parse the txt file into an nested array, because then I need to make an INSERT to a MySQL database. So the array format has to be in this way:

data_sql = [
   ['111111111'],
   ['222222222'],
   ['333333333']
]

Now I have the next code:

var data_sql = fs.readFileSync(`./uploads/${filename}`, 'utf8').split(/\r?\n/);

But it's saving the array like this:

data_sql = [
  '111111111', 
  '222222222',
  '333333333'
]

1 Answer 1

2

You can convert every entry to an array with a single item, like this

const formatedEntries = data_sql.map(entry => ([entry]))

Sign up to request clarification or add additional context in comments.

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.