Skip to content

Instantly share code, notes, and snippets.

@gaurangrshah
Created April 12, 2021 18:54
Show Gist options
  • Save gaurangrshah/becee5395cb2b4774ca614c013b3a34f to your computer and use it in GitHub Desktop.
Save gaurangrshah/becee5395cb2b4774ca614c013b3a34f to your computer and use it in GitHub Desktop.
export function createFormObject(inputsElements) {
/**
* #SCOPE: takes in an array of inputs and returns a single object with the shape
* {[input.name]L input.value}
*/
return inputsElements.reduce(
(obj, item) => ({ ...obj, [item.name]: item.value.trim() }), // trim whitespace
{}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment