Form to object

JavaScript, Browser, Object · Oct 19, 2020

Encodes a set of form elements as an object.

const formToObject = form =>
  Array.from(new FormData(form)).reduce(
    (acc, [key, value]) => ({
      ...acc,
      [key]: value
    }),
    {}
  );
formToObject(document.querySelector('#form'));
// { email: 'test@email.com', name: 'Test Name' }

More like this

  • Serialize form

    Encodes a set of form elements as a query string.

    JavaScript, Browser · Oct 22, 2020

  • Vertical offset of element

    Finds the distance from a given element to the top of the document.

    JavaScript, Browser · Jan 5, 2021

  • Array to HTML list

    Converts the given array elements into <li> tags and appends them to the list of the given id.

    JavaScript, Browser · Oct 20, 2020