Categories
JavaScript Answers

How to append an array to form data in JavaScript?

Spread the love

To append an array to form data in JavaScript, we convert it into a JSON string.

For instance, we write

const tags = ["this", "is", "an", "array"];
formData.append("tags", JSON.stringify(tags));

to call append with the key and the JSON array string converted from the tags array.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *