How To Append Array Of Objects Through Form Data In Javascript
I have dependents array, which has multiple objects. I need to send that array of objects through form data. I have gone through so many tries but cannot get correct solution
Solution 1:
You can use Array#forEach to accomplish this... however your array elements will be stringified obejcts.
const dependents = [{name: "ashraf", number: 96546},{name: "himanshu", number: 98766}]
const data = newFormData();
dependents.forEach(item => {
data.append(`dependents[]`, JSON.stringify(item));
});
console.log(data.getAll('dependents[]'));
Post a Comment for "How To Append Array Of Objects Through Form Data In Javascript"