0 points

js-formAsObject


dashboard

Sun Oct 18 2020 17:02:05 GMT+0000 (UTC)

Posted by @aymanelya

const formToObject = form =>
  Array.from(new FormData(form)).reduce(
    (acc, [key, value]) => ({
      ...acc,
      [key]: value
    }),
    {}
  );

// Example
formToObject(document.querySelector('#form')); // { email: 'test@email.com', name: 'Test Name' }
content_copy Copy

https://blog.madza.dev/24-modern-es6-code-snippets-to-solve-practical-js-problems?guid