1

I am inserting dynamic records

var sql = "INSERT INTO Test (name, email, n) VALUES ?";
var values = [
    ['test', '[email protected]', 1],
    ['test', '[email protected]', 2],
    ['mark', '[email protected]', 3],
    ['pete', '[email protected]', 4]
];
conn.query(sql, [values], function(err) {
    if (err) throw err;
    conn.end();
});

here is example which is working fine

Now my data is here

var arr = category_ids.split(",");
for (var i = 0; i < arr.length; i++) {

}

How to make dynamic array of values in for loop

Thanks

1 Answer 1

2

You just need an array of arrays, like what values is in the example you provided.

Your example

var arr = category_ids.split(",");
var values = [ arr ];

or simply

var value = [ category_ids.split(",") ];
Sign up to request clarification or add additional context in comments.

1 Comment

How to create an array for that

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.