Level 3
let formData = new FormData();
data.forEach(element => {
formData.append("files[]", element.file, element.fileTitle) // check this out for more info: https://developer.mozilla.org/en-US/docs/Web/API/FormData/append#example
})
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi mates,
I have this array of objects below:
data: [
{file: File, fileTitle: "file1", description: "desc1"},
{file: File, fileTitle: "file2", description: "desc2"},
{file: File, fileTitle: "file3", description: "desc3"},
]
And I am trying to append this array to a FormData before I send a request to an API. However, I cannot figure out how do I append array objects. So far here's my code (processing)
let formData = new FormData();
data.forEach(element => {
formData.append() // what should I put here?
})
Your responses and help are much appreciated. Thank you so much in advance! :)
Please or to participate in this conversation.