Multi-dimension array field with URLSearchParams

const payload = new URLSearchParams()

  items.forEach((item, index) => {
    payload.append('payload[' + index + '][field_1]', item.field_1)
    payload.append('payload[' + index + '][field_2]', item.field_2)
  })

  return payload

Result:

Request Data
MIME Type: application/x-www-form-urlencoded
payload[0][field_1]: 89
payload[0][field_2]: 10

Leave a comment