Reputation: 437
I have some text that I receive from the user:
var text = ['Hello', 'World']; // this is the product of string.split(',')
I need to convert it into an array like this one:
var argument = [['Hello'], ['World']];
I need the input in this format so I can send multiple values to the db.
How can I do this elegantly?
Upvotes: 0
Views: 29
Reputation: 1074335
I can't think of anything more elegant for this than map
:
E.g.:
var argument = originalString.split(",").map(function(entry) {
return [entry];
});
Or if you've enabled ES6 on your NodeJS installation:
var argument = originalString.split(",").map((entry) => [entry]);
Upvotes: 3