0

I have HTML input elements with names like A[1], A[2], A[3]. I want to catch them in express this way:

var optcount = i + 1;
var columnA=req.body['A['+optcount+']'];

However it does not work.

If I have names like A1, then this works:

var columnA=req.body['A'+optcount];

Any suggestions?

lebelinoz
  • 4,890
  • 10
  • 33
  • 56
emre deli
  • 83
  • 1
  • 9

1 Answers1

2

For a quick hack,

var optcount = i + 1;

var prop = 'A[' + optcount + ']';

var columnA=req.body[prop];

Should work.

You should be escaping characters to have a better optimized solution, look at these -> Is there a RegExp.escape function in Javascript? and How to escape regular expression in javascript?

Sudhansu Choudhary
  • 3,322
  • 3
  • 19
  • 30