To append array to FormData and send via AJAX with JavaScript, we create a FormData
object.
For instance, we write
const formData = new FormData();
const arr = ["this", "is", "an", "array"];
for (const a of arr) {
formData.append("arr[]", a);
}
to loop through the arr
array items with a for-of loop.
In the loop, we call formData.append
with the key and the value to append to the form data object.