I'm using express 4.16.
app.use(express.json());
...
router.post('/add', function (req, res, next) {
var course = req.body;
console.log(course);
});
the result looks like:
{
course_name: 'xxx',
course_start_date: '01-02-2019',
course_end_date: '15-02-2019',
'days[0][dayIdx]': '1',
'days[0][from]': '16:45',
'days[0][to]': '17:00',
'days[1][dayIdx]': '2',
'days[1][from]': '17:45',
'days[1][to]': '17:30'
}
what i'm looking for is having the following:
{
course_name: 'xxx',
course_start_date: '01-02-2019',
course_end_date: '15-02-2019',
'days':[
{'dayIdx': '1', 'from': '16:45', 'to': '17:00'},
{'dayIdx': '2', 'from': '17:45', 'to': '17:30'}
]
}
the input I send to the node is already contains an Array:
any elegant way or a library rather than iterating the keys and create the arrays manually?