I have an HTML form with an array of checkboxes (using []
naming). I need to be able to process this with express. I\'m using body-parser.
My approach requires no javascript on client side. Add hidden fields as many as your checkboxes with same names
body parser will parse checked items as array and string others
I meant
If your option[1] is checked then body parser will parse it like
{option:['0', ['0', '1'], '0']}
And here is the modifier
req.body.option = req.body.option.map(item => (Array.isArray(item) && item[1]) || null);
so now body will be
{option: [null, '1', null]}