0

I have a form where with some name attribute arrays. Currently, I have two problems.

(1) Once the form has been submitted, I am not able to parse the array values inside itemName[], itemValue[], itemQuantity[].

(2) I do not why itemName[], itemValue[], itemQuantity[] are strings in the object.

Could anyone advise what I did wrong?

{ sessionUser: '5ae767331e2086537a6026be',
  senderName: 'Mr. Camden Denesik',
  senderPhone: '411-431-6729 x28435',
  senderEmail: 'Pink.Boyer5@yahoo.com',
  senderAddress: '3324 Marvin Hollow',
  senderCity: 'South Ariannaland',
  senderProvince: 'Iowa',
  senderPostalCode: '61394-2622',
  senderCountry: 'Libyan Arab Jamahiriya',
  recipientName: 'Mac Keeling',
  recipientIdNumber: '17462',
  recipientPhone: '009-180-3472',
  recipientEmail: 'Lucas_Schultz67@gmail.com',
  recipientAddress: '91928 Bobbie Port',
  recipientCity: 'Catharineside',
  recipientProvince: 'Iowa',
  recipientPostalCode: '80415',
  recipientCountry: 'Montserrat',
  'itemName[]': [ 'microchip', 'Kaka' ],
  'itemValue[]': [ '135.00', '100' ],
  'itemQuantity[]': [ '95065', '20' ],
  itemTotalValue: '4.00',
  insurance: 'on',
  cargoInsurance: '893.00' }
ApplePie
  • 1,155
  • 3
  • 12
  • 30
  • (1) Yes, you can. If you couldn't, then you wouldn't be able to log that object! Did you mean that you don't know how to access the property? – Quentin May 07 '18 at 21:11
  • 2
    (2) A property can be represented by a string or an identifier but `[` and `]` are characters that can't appear in an identifier. – Quentin May 07 '18 at 21:11
  • @Quentin yes, you are correct. I was not clear. What I really wanted was to access itemName[] itemValue[] and itemQuantity[] – ApplePie May 07 '18 at 21:53

1 Answers1

0

(2) This is how javascript handle attributes with special characters, try accessing the variables like a dictionary array obj['itemName[]']. The best way to avoid this is to remove the [] from the attribute names.

As for (1) I don't fully understand your problem but I guess it has something to do with the inability to access the variables.

Keegan Ferrett
  • 344
  • 2
  • 3
  • 11