How to inspect FormData?

前端 未结 15 1304
悲&欢浪女
悲&欢浪女 2020-11-22 08:23

I\'ve tried console.log and looping through it using for in.

Here it the MDN Reference on FormData.

Both attempts are in this fi

15条回答
  •  南笙
    南笙 (楼主)
    2020-11-22 08:32

    Here's a function to log entries of a FormData object to the console as an object.

    export const logFormData = (formData) => {
        const entries = formData.entries();
        const result = {};
        let next;
        let pair;
        while ((next = entries.next()) && next.done === false) {
            pair = next.value;
            result[pair[0]] = pair[1];
        }
        console.log(result);
    };
    

    MDN doc on .entries()

    MDN doc on .next() and .done

提交回复
热议问题