FormData to JSON entries() not a function error in SDK35

I am trying to convert FormData to simple JSON format such as {“val1” :1 , “val2” : 3} from FormData object, currently FormData gives a multi array.

I get error entries() is not a function error, not sure why? Any alternative ways to make FormData simple JSON object to pass to API via fetch()

                const {email, password, fname} = this.state;
                var formData = new FormData();
                formData.append('email', email);
                formData.append('password', password);
                formData.append('fname', fname);

                this.setState({spinner: true});

                let jsonObject = {};

                for (const [key, value]  of formData.entries()) {
                    jsonObject[key] = value;
                }

Hi. If you are going to send the JSON via fetch then do you even need the FormData?

If you do need it for some reason, could you add the data to JSON and later loop over them to add them to the FormData object?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.