formdata array of objects

Solutions on MaxInterview for formdata array of objects by the best coders in the world

showing results for - "formdata array of objects"
Juan David
21 Jan 2019
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
Juan Diego
12 Oct 2020
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