I am storing an array from jade into mongodb.
Eg. input(name='name[]',type='text')->Firstname,input(name='name[]',type='text')->lastname (just eg). So i have a name array. I have stored into mongodb using the schema ('name':Array) and the values get stored as 'name':[['firsname','lastname']].
But when accessing back in jade, name[0] contains both firstname and last name values as a singe string.
name[0] outputs "firstname,lastname". I want it as the original array, like name[0]='firstname' and name[1]='lastname'.Please help me out. Trying for more than a week!
You have an Array of an Array:
'name':[['firsname','lastname']]
So instead of name, name[0] is the "original Array" and to access each value from it you need to use:
name[0][0] // first name
name[0][1] // last name
Otherwise, to have name be a single Array, that depends on how you're currently modifying the model. But, simply setting it to the form data should be sufficient:
yourModel.name = req.body.name;
Then you should be able to use:
name[0] // first name
name[1] // last name