Fix an Acrobat JavaScript Array That Skips PDF Form Fields
Question details
Populate all intended PDF form fields from a nested JavaScript array in Adobe Acrobat.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A JavaScript loop uses an array containing three inner arrays of PDF form field names.
- Observed behavior
- The loop iterates over the three outer-array indexes rather than every field name.
Check the exact field names in Acrobat's Prepare a Form tool and identify the value each group of fields should receive. Open the JavaScript containing the fields array so you can update its loop.
Loop Through Each Nested Array of Acrobat Form Fields
Use an outer loop for each group and an inner loop for every field name in that group.
In your Acrobat JavaScript, confirm that fields contains inner arrays of field-name strings, such as [["Field1", "Field2"], ["Field3"], ["Field4"]]. Replace these examples with your actual field names.
Replace the outer-only loop with nested loops. For example, define values with one desired value per group, then use: var values = ["Value 1", "Value 2", "Value 3"]; for (var row = 0; row < fields.length; row++) { for (var column = 0; column < fields[row].length; column++) { var field = this.getField(fields[row][column]); if (field) field.value = values[row]; } }
Run the script in Acrobat and check each target field. If a field remains empty, compare its name in Prepare a Form with the corresponding string in fields.

Flatten the Field Names Before Looping
Use a single loop when you prefer to work with one list of field names.
Work With PDFs and Office Files in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office documents. Its format support makes it easy to bring existing files into your workflow, although it does not fix Adobe Acrobat JavaScript.

Frequently Asked Questions
Why does my loop see only indexes 0, 1, and 2?
The outer fields array contains three inner arrays, so its indexes are 0, 1, and 2. Add an inner loop and access each field name with fields[row][column].
How do I find the exact names of my PDF form fields?
Open the PDF in Acrobat and use Prepare a Form to inspect the form fields. Match each name exactly to the corresponding string in your JavaScript array.
What happens if this.getField cannot find a field?
It returns null. Check the result before assigning field.value, and verify the field name in Acrobat's Prepare a Form tool.
Can I give each group of fields a different value?
Yes. Store one value per group and assign values[row] inside the nested loop. If individual fields need different values, use additional column-based logic instead.




