Menu

gitpiper

formToObject javascript Code Snippet in 2024

browserobjectintermediate

Last Updated: 16 December 2024

Encodes a set of form elements as an object.

  • Use the FormData constructor to convert the HTML form to FormData and Array.from() to convert to an array.
  • Collect the object from the array using Array.prototype.reduce().
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' }

javascript snippet similar to formToObject For You in December 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️