1const formData = new FormData();
2for (let key in form) {
3 Array.isArray(form[key])
4 ? form[key].forEach(value => formData.append(key + '[]', value))
5 : formData.append(key, form[key]) ;
6}
7
1function createFormData(formData, key, data) {
2 if (data === Object(data) || Array.isArray(data)) {
3 for (var i in data) {
4 createFormData(formData, key + '[' + i + ']', data[i]);
5 }
6 } else {
7 formData.append(key, data);
8 }
9}
10