How to make an array of arrays for a multiple Insert in mysql with Node?

Asked

Viewed 79 times

0

I need to make a multi-value database, for that I need a array of array.

The first value of each array will be fixed and the second element I will change with a is probably:

var values = 
[
    ['281', 'Highway 71'],
    ['281', 'Lowstreet 4'],
    ['281', 'Apple st 652'],
    ['281', 'Mountain 21'],
    ['281', 'Valley 345'],
    ['281', 'Ocean blvd 2'],
    ['281', 'Green Grass 1']
];

1 answer

0

I figured out how to do:

for (let index = 0; index < list.length; index++) 
{
    sqlObj[index] = [lastId, list[index]];
}
  • 1

    And why does that solve the problem? Could you explain what you did in the code?

  • Of course @Woss ... To insert multiple data into the database with Node is required an array of arrays ( As can be seen in "Insert Multiple Records" here: link )

  • With the for I posted, at each position of an Array (sqlObj) it adds an array containing the last id (fixed) of an Insert I made + the list element I need...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.